Skip to content

Commit

Permalink
Fix Out of Memory error (thanks Derek)
Browse files Browse the repository at this point in the history
  • Loading branch information
jblanked committed Dec 5, 2024
1 parent 0cfcf38 commit 9bb3b3d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion flip_social.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion friends/flip_social_friends.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
6 changes: 0 additions & 6 deletions jsmn/jsmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions messages/flip_social_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 9bb3b3d

Please sign in to comment.