Просмотр исходного кода

Fix Out of Memory error (thanks Derek)

jblanked 1 год назад
Родитель
Сommit
9bb3b3d9ae
4 измененных файлов с 6 добавлено и 12 удалено
  1. 1 1
      flip_social.h
  2. 1 1
      friends/flip_social_friends.c
  3. 0 6
      jsmn/jsmn.c
  4. 4 4
      messages/flip_social_messages.c

+ 1 - 1
flip_social.h

@@ -14,7 +14,7 @@
 #define MAX_EXPLORE_USERS 50      // Maximum number of users to explore
 #define MAX_USER_LENGTH 32        // Maximum length of a username
 #define MAX_FRIENDS 50            // Maximum number of friends
-#define MAX_TOKENS 640            // Adjust based on expected JSON tokens
+#define MAX_TOKENS 576            // Adjust based on expected JSON tokens
 #define MAX_FEED_ITEMS 50         // Maximum number of feed items
 #define MAX_LINE_LENGTH 30
 #define MAX_MESSAGE_USERS 40 // Maximum number of users to display in the submenu

+ 1 - 1
friends/flip_social_friends.c

@@ -117,7 +117,7 @@ bool flip_social_parse_json_friends()
     submenu_set_header(app_instance->submenu_friends, "Friends");
 
     // Extract the users array from the JSON
-    char *json_users = get_json_value("friends", data_cstr, MAX_TOKENS);
+    char *json_users = get_json_value("friends", data_cstr, 128);
     if (json_users == NULL)
     {
         FURI_LOG_E(TAG, "Failed to parse friends array.");

+ 0 - 6
jsmn/jsmn.c

@@ -473,9 +473,6 @@ char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
             return NULL;
         }
 
-        // print amount of tokens
-        FURI_LOG_I("JSMM.H", "Amount of tokens: %d", ret);
-
         // Ensure that the root element is an object
         if (ret < 1 || tokens[0].type != JSMN_OBJECT)
         {
@@ -551,9 +548,6 @@ char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t
         return NULL;
     }
 
-    // print amount of tokens
-    FURI_LOG_I("JSMM.H", "Amount of tokens: %d", ret);
-
     // Ensure the root element is an array
     if (ret < 1 || tokens[0].type != JSMN_ARRAY)
     {

+ 4 - 4
messages/flip_social_messages.c

@@ -40,7 +40,7 @@ FlipSocialMessage *flip_social_user_messages_alloc()
         FURI_LOG_E(TAG, "Failed to allocate memory for messages");
         return NULL;
     }
-    for (size_t i = 0; i < MAX_MESSAGE_USERS; i++)
+    for (size_t i = 0; i < MAX_MESSAGES; i++)
     {
         if (messages->usernames[i] == NULL)
         {
@@ -410,15 +410,15 @@ bool flip_social_parse_json_messages()
     for (int i = 0; i < MAX_MESSAGES; i++)
     {
         // Parse each item in the array
-        char *item = get_json_array_value("conversations", i, data_cstr, 128);
+        char *item = get_json_array_value("conversations", i, data_cstr, 64);
         if (item == NULL)
         {
             break;
         }
 
         // Extract individual fields from the JSON object
-        char *sender = get_json_value("sender", item, 32);
-        char *content = get_json_value("content", item, 32);
+        char *sender = get_json_value("sender", item, 8);
+        char *content = get_json_value("content", item, 8);
 
         if (sender == NULL || content == NULL)
         {