Forráskód Böngészése

General Fixes + Handle NULL pointer

jblanked 1 éve
szülő
commit
f8b72b7a16

+ 1 - 1
alloc/flip_weather_alloc.c

@@ -108,7 +108,7 @@ FlipWeatherApp *flip_weather_app_alloc()
     }
 
     // Popup
-    if (!easy_flipper_set_popup(&app->popup_error, FlipWeatherViewPopupError, "[ERROR]", 0, 0, "Wifi Dev Board disconnected.\nPlease connect to the board.\nIf your board is connected,\nmake sure you have flashed\nyour WiFi Devboard with the\nlatest FlipperHTTP flash.", 0, 7, flip_weather_popup_callback, callback_to_submenu, &app->view_dispatcher, app))
+    if (!easy_flipper_set_popup(&app->popup_error, FlipWeatherViewPopupError, "[ERROR]", 0, 0, "Wifi Dev Board disconnected.\nIf your board is connected,\nmake sure you have the\nlatest FlipperHTTP flash.", 0, 12, flip_weather_popup_callback, callback_to_submenu, &app->view_dispatcher, app))
     {
         return NULL;
     }

BIN
assets/02-weather.png


+ 1 - 1
flipper_http/flipper_http.h

@@ -13,7 +13,7 @@
 #define HTTP_TAG "FlipWeather"            // change this to your app name
 #define http_tag "flip_weather"           // change this to your app id
 #define UART_CH (FuriHalSerialIdUsart)    // UART channel
-#define TIMEOUT_DURATION_TICKS (5 * 1000) // 5 seconds
+#define TIMEOUT_DURATION_TICKS (6 * 1000) // 6 seconds
 #define BAUDRATE (115200)                 // UART baudrate
 #define RX_BUF_SIZE 1024                  // UART RX buffer size
 #define RX_LINE_BUFFER_SIZE 4096          // UART RX line buffer size (increase for large responses)

+ 14 - 0
parse/flip_weather_parse.c

@@ -123,6 +123,13 @@ void process_geo_location()
         char *latitude = get_json_value("latitude", fhttp.last_response, MAX_TOKENS);
         char *longitude = get_json_value("longitude", fhttp.last_response, MAX_TOKENS);
 
+        if (city == NULL || region == NULL || country == NULL || latitude == NULL || longitude == NULL)
+        {
+            FURI_LOG_E(TAG, "Failed to get geo location data");
+            fhttp.state = ISSUE;
+            return;
+        }
+
         snprintf(city_data, 64, "City: %s", city);
         snprintf(region_data, 64, "Region: %s", region);
         snprintf(country_data, 64, "Country: %s", country);
@@ -152,6 +159,13 @@ void process_weather()
         char *snowfall = get_json_value("snowfall", current_data, MAX_TOKENS);
         char *time = get_json_value("time", current_data, MAX_TOKENS);
 
+        if (current_data == NULL || temperature == NULL || precipitation == NULL || rain == NULL || showers == NULL || snowfall == NULL || time == NULL)
+        {
+            FURI_LOG_E(TAG, "Failed to get weather data");
+            fhttp.state = ISSUE;
+            return;
+        }
+
         // replace the "T" in time with a space
         char *ptr = strstr(time, "T");
         if (ptr != NULL)