From ab3fc6413ea25497ff6c60fde915e729f028b50e Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:19:51 +0000 Subject: [PATCH] Less pointer abuse casting --nobuild --- .../main/nfc/plugins/supported_cards/ndef.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/applications/main/nfc/plugins/supported_cards/ndef.c b/applications/main/nfc/plugins/supported_cards/ndef.c index 22663fdf6..a40f59a16 100644 --- a/applications/main/nfc/plugins/supported_cards/ndef.c +++ b/applications/main/nfc/plugins/supported_cards/ndef.c @@ -6,6 +6,7 @@ #include "nfc_supported_card_plugin.h" +#include #include #include @@ -161,18 +162,18 @@ static void parse_ndef_wifi(FuriString* str, const uint8_t* payload, uint32_t pa size_t i = 0; while(i < payload_len) { - uint16_t field_id = __REV16(*(uint16_t*)&payload[i]); + uint16_t field_id = nfc_util_bytes2num(payload + i, 2); i += 2; - uint16_t field_len = __REV16(*(uint16_t*)&payload[i]); + uint16_t field_len = nfc_util_bytes2num(payload + i, 2); i += 2; if(field_id == CREDENTIAL_FIELD_ID) { furi_string_cat(str, "WiFi\n"); size_t start_position = i; while(i < start_position + field_len) { - uint16_t cfg_id = __REV16(*(uint16_t*)&payload[i]); + uint16_t cfg_id = nfc_util_bytes2num(payload + i, 2); i += 2; - uint16_t cfg_len = __REV16(*(uint16_t*)&payload[i]); + uint16_t cfg_len = nfc_util_bytes2num(payload + i, 2); i += 2; if(i + cfg_len > start_position + field_len) { @@ -195,7 +196,7 @@ static void parse_ndef_wifi(FuriString* str, const uint8_t* payload, uint32_t pa if(cfg_len != AUTH_TYPE_EXPECTED_SIZE) { return; } - short auth_type = __REV16(*(uint16_t*)&payload[i]); + short auth_type = nfc_util_bytes2num(payload + i, 2); i += 2; const char* auth; switch(auth_type) { @@ -317,7 +318,7 @@ static const uint8_t* parse_ndef_message( if(short_record) { payload_len = *cur++; } else { - payload_len = __REV(*(uint32_t*)cur); + payload_len = nfc_util_bytes2num(cur, 4); cur += 4; } @@ -390,7 +391,7 @@ static bool ndef_parse(const NfcDevice* device, FuriString* parsed_data) { cur = end; break; } - len = __REV16(*(uint16_t*)(++cur)); + len = nfc_util_bytes2num(++cur, 2); cur += 2; } if(cur + len >= end) { @@ -432,7 +433,7 @@ static bool ndef_parse(const NfcDevice* device, FuriString* parsed_data) { cur = end; break; } - cur += __REV16(*(uint16_t*)(cur + 1)) + 3; // Shift by TLV length + cur += nfc_util_bytes2num(cur + 1, 2) + 3; // Shift by TLV length } break;