Skip to content

Commit 9bb3b3d

Browse files
committed
Fix Out of Memory error (thanks Derek)
1 parent 0cfcf38 commit 9bb3b3d

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

flip_social.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define MAX_EXPLORE_USERS 50 // Maximum number of users to explore
1515
#define MAX_USER_LENGTH 32 // Maximum length of a username
1616
#define MAX_FRIENDS 50 // Maximum number of friends
17-
#define MAX_TOKENS 640 // Adjust based on expected JSON tokens
17+
#define MAX_TOKENS 576 // Adjust based on expected JSON tokens
1818
#define MAX_FEED_ITEMS 50 // Maximum number of feed items
1919
#define MAX_LINE_LENGTH 30
2020
#define MAX_MESSAGE_USERS 40 // Maximum number of users to display in the submenu

friends/flip_social_friends.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool flip_social_parse_json_friends()
117117
submenu_set_header(app_instance->submenu_friends, "Friends");
118118

119119
// Extract the users array from the JSON
120-
char *json_users = get_json_value("friends", data_cstr, MAX_TOKENS);
120+
char *json_users = get_json_value("friends", data_cstr, 128);
121121
if (json_users == NULL)
122122
{
123123
FURI_LOG_E(TAG, "Failed to parse friends array.");

jsmn/jsmn.c

-6
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,6 @@ char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
473473
return NULL;
474474
}
475475

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

554-
// print amount of tokens
555-
FURI_LOG_I("JSMM.H", "Amount of tokens: %d", ret);
556-
557551
// Ensure the root element is an array
558552
if (ret < 1 || tokens[0].type != JSMN_ARRAY)
559553
{

messages/flip_social_messages.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ FlipSocialMessage *flip_social_user_messages_alloc()
4040
FURI_LOG_E(TAG, "Failed to allocate memory for messages");
4141
return NULL;
4242
}
43-
for (size_t i = 0; i < MAX_MESSAGE_USERS; i++)
43+
for (size_t i = 0; i < MAX_MESSAGES; i++)
4444
{
4545
if (messages->usernames[i] == NULL)
4646
{
@@ -410,15 +410,15 @@ bool flip_social_parse_json_messages()
410410
for (int i = 0; i < MAX_MESSAGES; i++)
411411
{
412412
// Parse each item in the array
413-
char *item = get_json_array_value("conversations", i, data_cstr, 128);
413+
char *item = get_json_array_value("conversations", i, data_cstr, 64);
414414
if (item == NULL)
415415
{
416416
break;
417417
}
418418

419419
// Extract individual fields from the JSON object
420-
char *sender = get_json_value("sender", item, 32);
421-
char *content = get_json_value("content", item, 32);
420+
char *sender = get_json_value("sender", item, 8);
421+
char *content = get_json_value("content", item, 8);
422422

423423
if (sender == NULL || content == NULL)
424424
{

0 commit comments

Comments
 (0)