Browse Source

Remove strcat

jblanked 1 year ago
parent
commit
f8edda5e75
3 changed files with 11 additions and 10 deletions
  1. 3 1
      assets/FlipperHTTP/flipper_http.h
  2. 7 4
      flipper_http.h
  3. 1 5
      web_crawler_callback.h

+ 3 - 1
assets/FlipperHTTP/flipper_http.h

@@ -23,6 +23,8 @@ void flipper_http_rx_callback(const char *line, void *context);
 // Function to save received data to a file
 bool flipper_http_save_received_data(size_t bytes_received, const char line_buffer[]);
 
+static bool flipper_http_connect_wifi();
+
 // Define GPIO pins for UART
 GpioPin test_pins[2] = {
     {.port = GPIOA, .pin = LL_GPIO_PIN_7}, // USART1_RX
@@ -364,7 +366,7 @@ bool flipper_http_disconnect_wifi()
 }
 
 // Function to connect to WiFi (returns true if successful)
-bool flipper_http_connect_wifi()
+static bool flipper_http_connect_wifi()
 {
     const char *command = "[WIFI/CONNECT]";
     if (!flipper_http_send_data(command))

+ 7 - 4
flipper_http.h

@@ -468,17 +468,20 @@ void flipper_http_rx_callback(const char *line, void *context)
             if (fhttp.received_data)
             {
                 strcpy(fhttp.received_data, line);
-                strcat(fhttp.received_data, "\n");
+                fhttp.received_data[strlen(line)] = '\n';     // Add newline
+                fhttp.received_data[strlen(line) + 1] = '\0'; // Null terminator
             }
         }
         else
         {
-            size_t new_size = strlen(fhttp.received_data) + strlen(line) + 2; // +2 for newline and null terminator
+            size_t current_len = strlen(fhttp.received_data);
+            size_t new_size = current_len + strlen(line) + 2; // +2 for newline and null terminator
             fhttp.received_data = (char *)realloc(fhttp.received_data, new_size);
             if (fhttp.received_data)
             {
-                strcat(fhttp.received_data, line);
-                strcat(fhttp.received_data, "\n");
+                memcpy(fhttp.received_data + current_len, line, strlen(line)); // Copy line at the end of the current data
+                fhttp.received_data[current_len + strlen(line)] = '\n';        // Add newline
+                fhttp.received_data[current_len + strlen(line) + 1] = '\0';    // Null terminator
             }
         }
 

+ 1 - 5
web_crawler_callback.h

@@ -65,16 +65,12 @@ static void web_crawler_view_draw_callback(Canvas *canvas, void *context)
                 canvas_draw_str(canvas, 0, 10, "Receiving and parsing data...");
                 already_success = true;
             }
-            else if (get_success && fhttp.state == IDLE && fhttp.received_data == NULL && already_success)
+            else if (get_success && fhttp.state == IDLE)
             {
                 already_success = true;
                 canvas_draw_str(canvas, 0, 10, "Data saved to file.");
                 canvas_draw_str(canvas, 0, 20, "Press BACK to return.");
             }
-            else if (get_success && fhttp.state == IDLE && fhttp.received_data == NULL && !already_success)
-            {
-                canvas_draw_str(canvas, 0, 10, "Receiving and parsing data...");
-            }
             else
             {
                 if (fhttp.state == ISSUE)