Przeglądaj źródła

NFC Maker: Improve memory management

Willy-JL 1 rok temu
rodzic
commit
1209ea576c

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_bluetooth.c

@@ -16,7 +16,7 @@ void nfc_maker_scene_bluetooth_on_enter(void* context) {
 
     byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:");
 
-    for(size_t i = 0; i < MAC_INPUT_LEN; i++) {
+    for(size_t i = 0; i < sizeof(app->mac_buf); i++) {
         app->mac_buf[i] = 0x69;
     }
 
@@ -26,7 +26,7 @@ void nfc_maker_scene_bluetooth_on_enter(void* context) {
         NULL,
         app,
         app->mac_buf,
-        MAC_INPUT_LEN);
+        sizeof(app->mac_buf));
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewByteInput);
 }

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_contact.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_contact_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter First Name:");
 
-    strlcpy(app->small_buf1, "John", SMALL_INPUT_LEN);
+    strlcpy(app->small_buf1, "John", sizeof(app->small_buf1));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_contact_text_input_callback,
         app,
         app->small_buf1,
-        SMALL_INPUT_LEN,
+        sizeof(app->small_buf1),
         true);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_contact_last.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_contact_last_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Last Name:");
 
-    strlcpy(app->small_buf2, "Smith", SMALL_INPUT_LEN);
+    strlcpy(app->small_buf2, "Smith", sizeof(app->small_buf2));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_contact_last_text_input_callback,
         app,
         app->small_buf2,
-        SMALL_INPUT_LEN,
+        sizeof(app->small_buf2),
         true);
 
     text_input_set_minimum_length(text_input, 0);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_contact_mail.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_contact_mail_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Mail Address:");
 
-    strlcpy(app->mail_buf, "johnsmith@email.com", MAIL_INPUT_LEN);
+    strlcpy(app->mail_buf, "johnsmith@email.com", sizeof(app->mail_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_contact_mail_text_input_callback,
         app,
         app->mail_buf,
-        MAIL_INPUT_LEN,
+        sizeof(app->mail_buf),
         true);
 
     text_input_set_minimum_length(text_input, 0);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_contact_phone.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_contact_phone_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Phone Number:");
 
-    strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);
+    strlcpy(app->phone_buf, "+", sizeof(app->phone_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_contact_phone_text_input_callback,
         app,
         app->phone_buf,
-        PHONE_INPUT_LEN,
+        sizeof(app->phone_buf),
         false);
 
     text_input_set_minimum_length(text_input, 0);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_contact_url.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_contact_url_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter URL Link:");
 
-    strlcpy(app->big_buf, "momentum-fw.dev", BIG_INPUT_LEN);
+    strlcpy(app->big_buf, "momentum-fw.dev", sizeof(app->big_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_contact_url_text_input_callback,
         app,
         app->big_buf,
-        BIG_INPUT_LEN,
+        sizeof(app->big_buf),
         true);
 
     text_input_set_minimum_length(text_input, 0);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_https.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_https_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Https Link:");
 
-    strlcpy(app->big_buf, "momentum-fw.dev", BIG_INPUT_LEN);
+    strlcpy(app->big_buf, "momentum-fw.dev", sizeof(app->big_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_https_text_input_callback,
         app,
         app->big_buf,
-        BIG_INPUT_LEN,
+        sizeof(app->big_buf),
         true);
 
     text_input_show_illegal_symbols(text_input, true);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_mail.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_mail_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Mail Address:");
 
-    strlcpy(app->mail_buf, "johnsmith@email.com", MAIL_INPUT_LEN);
+    strlcpy(app->mail_buf, "johnsmith@email.com", sizeof(app->mail_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_mail_text_input_callback,
         app,
         app->mail_buf,
-        MAIL_INPUT_LEN,
+        sizeof(app->mail_buf),
         true);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_phone.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_phone_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Phone Number:");
 
-    strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);
+    strlcpy(app->phone_buf, "+", sizeof(app->phone_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_phone_text_input_callback,
         app,
         app->phone_buf,
-        PHONE_INPUT_LEN,
+        sizeof(app->phone_buf),
         false);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);

+ 12 - 12
nfc_maker/scenes/nfc_maker_scene_save_generate.c

@@ -14,7 +14,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x02; // Media-type [RFC 2046]
         type = "application/vnd.bluetooth.ep.oob";
 
-        data_len = MAC_INPUT_LEN;
+        data_len = sizeof(app->mac_buf);
         payload_len = data_len + 2;
         payload = payload_it = malloc(payload_len);
 
@@ -36,15 +36,15 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
             vcard,
             "FN:%s%s%s\r\n",
             app->small_buf1,
-            strnlen(app->small_buf2, SMALL_INPUT_LEN) ? " " : "",
+            app->small_buf2[0] ? " " : "",
             app->small_buf2);
-        if(strnlen(app->mail_buf, MAIL_INPUT_LEN)) {
+        if(app->mail_buf[0]) {
             furi_string_cat_printf(vcard, "EMAIL:%s\r\n", app->mail_buf);
         }
-        if(strnlen(app->phone_buf, PHONE_INPUT_LEN)) {
+        if(app->phone_buf[0]) {
             furi_string_cat_printf(vcard, "TEL:%s\r\n", app->phone_buf);
         }
-        if(strnlen(app->big_buf, BIG_INPUT_LEN)) {
+        if(app->big_buf[0]) {
             furi_string_cat_printf(vcard, "URL:%s\r\n", app->big_buf);
         }
         furi_string_cat_printf(vcard, "END:VCARD\r\n");
@@ -60,7 +60,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x01; // NFC Forum well-known type [NFC RTD]
         type = "U";
 
-        data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
+        data_len = strlen(app->big_buf);
         payload_len = data_len + 1;
         payload = payload_it = malloc(payload_len);
 
@@ -73,7 +73,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x01; // NFC Forum well-known type [NFC RTD]
         type = "U";
 
-        data_len = strnlen(app->mail_buf, MAIL_INPUT_LEN);
+        data_len = strlen(app->mail_buf);
         payload_len = data_len + 1;
         payload = payload_it = malloc(payload_len);
 
@@ -86,7 +86,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x01; // NFC Forum well-known type [NFC RTD]
         type = "U";
 
-        data_len = strnlen(app->phone_buf, PHONE_INPUT_LEN);
+        data_len = strlen(app->phone_buf);
         payload_len = data_len + 1;
         payload = payload_it = malloc(payload_len);
 
@@ -99,7 +99,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x01; // NFC Forum well-known type [NFC RTD]
         type = "T";
 
-        data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
+        data_len = strlen(app->big_buf);
         payload_len = data_len + 3;
         payload = payload_it = malloc(payload_len);
 
@@ -114,7 +114,7 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
         tnf = 0x01; // NFC Forum well-known type [NFC RTD]
         type = "U";
 
-        data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
+        data_len = strlen(app->big_buf);
         payload_len = data_len + 1;
         payload = payload_it = malloc(payload_len);
 
@@ -129,8 +129,8 @@ size_t nfc_maker_scene_save_generate_populate_ndef_buffer(NfcMaker* app) {
 
         // https://android.googlesource.com/platform/packages/apps/Nfc/+/refs/heads/main/src/com/android/nfc/NfcWifiProtectedSetup.java
         // https://github.com/bparmentier/WiFiKeyShare/blob/master/app/src/main/java/be/brunoparmentier/wifikeyshare/utils/NfcUtils.java
-        uint8_t ssid_len = strnlen(app->small_buf1, SMALL_INPUT_LEN);
-        uint8_t pass_len = strnlen(app->small_buf2, SMALL_INPUT_LEN);
+        uint8_t ssid_len = strlen(app->small_buf1);
+        uint8_t pass_len = strlen(app->small_buf2);
         uint8_t data_len = ssid_len + pass_len;
         payload_len = data_len + 39;
         payload = payload_it = malloc(payload_len);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_save_name.c

@@ -25,7 +25,7 @@ void nfc_maker_scene_save_name_on_enter(void* context) {
     furi_string_replace(prefix, " Plus", "+"); // NTAG I2C+
     furi_string_replace(prefix, " (Unknown)", "");
     furi_string_replace_all(prefix, " ", "_");
-    name_generator_make_auto(app->save_buf, BIG_INPUT_LEN, furi_string_get_cstr(prefix));
+    name_generator_make_auto(app->save_buf, sizeof(app->save_buf), furi_string_get_cstr(prefix));
     furi_string_free(prefix);
 
     text_input_set_result_callback(
@@ -33,7 +33,7 @@ void nfc_maker_scene_save_name_on_enter(void* context) {
         nfc_maker_scene_save_name_text_input_callback,
         app,
         app->save_buf,
-        BIG_INPUT_LEN,
+        sizeof(app->save_buf),
         true);
 
     ValidatorIsFile* validator_is_file =

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_text.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_text_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Text Note:");
 
-    strlcpy(app->big_buf, "Lorem ipsum", BIG_INPUT_LEN);
+    strlcpy(app->big_buf, "Lorem ipsum", sizeof(app->big_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_text_text_input_callback,
         app,
         app->big_buf,
-        BIG_INPUT_LEN,
+        sizeof(app->big_buf),
         true);
 
     text_input_show_illegal_symbols(text_input, true);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_url.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_url_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter Plain URL:");
 
-    strlcpy(app->big_buf, "https://momentum-fw.dev", BIG_INPUT_LEN);
+    strlcpy(app->big_buf, "https://momentum-fw.dev", sizeof(app->big_buf));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_url_text_input_callback,
         app,
         app->big_buf,
-        BIG_INPUT_LEN,
+        sizeof(app->big_buf),
         true);
 
     text_input_show_illegal_symbols(text_input, true);

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_wifi.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_wifi_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter WiFi SSID:");
 
-    strlcpy(app->small_buf1, "Bill Wi the Science Fi", SMALL_INPUT_LEN);
+    strlcpy(app->small_buf1, "Bill Wi the Science Fi", sizeof(app->small_buf1));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_wifi_text_input_callback,
         app,
         app->small_buf1,
-        SMALL_INPUT_LEN,
+        sizeof(app->small_buf1),
         true);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);

+ 1 - 1
nfc_maker/scenes/nfc_maker_scene_wifi_auth.c

@@ -65,7 +65,7 @@ bool nfc_maker_scene_wifi_auth_on_event(void* context, SceneManagerEvent event)
         if(event.event == WifiAuthenticationOpen) {
             scene_manager_set_scene_state(
                 app->scene_manager, NfcMakerSceneWifiEncr, WifiEncryptionNone);
-            strcpy(app->small_buf2, "");
+            strlcpy(app->small_buf2, "", sizeof(app->small_buf2));
             scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
         } else {
             scene_manager_set_scene_state(

+ 2 - 2
nfc_maker/scenes/nfc_maker_scene_wifi_pass.c

@@ -16,14 +16,14 @@ void nfc_maker_scene_wifi_pass_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Enter WiFi Password:");
 
-    strlcpy(app->small_buf2, "244466666", SMALL_INPUT_LEN);
+    strlcpy(app->small_buf2, "244466666", sizeof(app->small_buf2));
 
     text_input_set_result_callback(
         text_input,
         nfc_maker_scene_wifi_pass_text_input_callback,
         app,
         app->small_buf2,
-        SMALL_INPUT_LEN,
+        sizeof(app->small_buf2),
         true);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);