summaryrefslogtreecommitdiff
path: root/apps/examples/wgetjson/wgetjson_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/examples/wgetjson/wgetjson_main.c')
-rw-r--r--apps/examples/wgetjson/wgetjson_main.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/apps/examples/wgetjson/wgetjson_main.c b/apps/examples/wgetjson/wgetjson_main.c
index 724b3b5b1..7dafbcb44 100644
--- a/apps/examples/wgetjson/wgetjson_main.c
+++ b/apps/examples/wgetjson/wgetjson_main.c
@@ -83,9 +83,9 @@
* Private Data
****************************************************************************/
-static char *g_json_buff = NULL;
-static int g_json_bufflen = 0;
-static bool g_has_json = false;
+static FAR char *g_json_buff = NULL;
+static int g_json_bufflen = 0;
+static bool g_has_json = false;
/****************************************************************************
* Private Functions
@@ -113,7 +113,9 @@ static void wgetjson_postdebug_callback(FAR char **buffer, int offset,
static void wgetjson_callback(FAR char **buffer, int offset, int datend,
FAR int *buflen, FAR void *arg)
{
- int len = datend - offset,org=len;
+ FAR char *new_json_buff;
+ int len = datend - offset;
+ int org = len;
if (len <= 0)
{
@@ -140,10 +142,14 @@ static void wgetjson_callback(FAR char **buffer, int offset, int datend,
len = CONFIG_EXAMPLES_WGETJSON_MAXSIZE - g_json_bufflen;
}
- g_json_buff = realloc(g_json_buff, g_json_bufflen + len + 1);
- memcpy(&g_json_buff[g_json_bufflen-1], &((*buffer)[offset]), len);
- g_json_buff[g_json_bufflen + len] = 0;
- g_json_bufflen += org;
+ new_json_buff = (FAR char *)realloc(g_json_buff, g_json_bufflen + len + 1);
+ if (new_json_buff)
+ {
+ g_json_buff = new_json_buff;
+ memcpy(&g_json_buff[g_json_bufflen-1], &((*buffer)[offset]), len);
+ g_json_buff[g_json_bufflen + len] = 0;
+ g_json_bufflen += org;
+ }
}
}