From 4f0d78f1d91619b2cc67fade8c23ba88d6614371 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Mon, 8 May 2023 23:56:28 -0500 Subject: [PATCH] Fix cppcheck warnings --- amplifiers/expert/expert.c | 7 +- cppcheck.sh | 4 +- lib/asyncpipe.c | 5 +- lib/cJSON.c | 1316 ++++++++++++++---------------------- lib/cJSON.h | 15 +- rigs/adat/adat.c | 2 +- rigs/alinco/dx77.c | 6 +- rigs/alinco/dxsr8.c | 8 +- rigs/aor/aor.c | 7 +- 9 files changed, 532 insertions(+), 838 deletions(-) diff --git a/amplifiers/expert/expert.c b/amplifiers/expert/expert.c index 8bbdbd825..ad0722c79 100644 --- a/amplifiers/expert/expert.c +++ b/amplifiers/expert/expert.c @@ -129,7 +129,12 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, char cmdbuf[64]; int checksum = 0; - rig_debug(RIG_DEBUG_VERBOSE, "%s called, cmd=%s\n", __func__, cmd); + if (cmd) { rig_debug(RIG_DEBUG_VERBOSE, "%s called, cmd=%s\n", __func__, cmd); } + else + { + rig_debug(RIG_DEBUG_ERR, "%s: cmd empty\n", __func__); + return -RIG_EINVAL; + } if (!amp) { return -RIG_EINVAL; } diff --git a/cppcheck.sh b/cppcheck.sh index 13c282ad1..3b6d535ee 100755 --- a/cppcheck.sh +++ b/cppcheck.sh @@ -21,7 +21,9 @@ SUPPRESS="\ --suppress=*:extra/gnuradio/ssb.h \ --suppress=*:extra/gnuradio/wfm.h \ --suppress=*:extra/gnuradio/wfm.h \ ---suppress=*:extra/gnuradio/HrAGC.h +--suppress=*:extra/gnuradio/HrAGC.h \ +--suppress=*:extra/gnuradio/gnuradio.cc \ +--suppress=missingIncludeSystem #CHECK="\ #-D RIG_LEVEL_LINEOUT=1 \ diff --git a/lib/asyncpipe.c b/lib/asyncpipe.c index 417825941..bca2e936e 100644 --- a/lib/asyncpipe.c +++ b/lib/asyncpipe.c @@ -43,6 +43,7 @@ int async_pipe_create(hamlib_async_pipe_t **pipe_out, if (!pipe->read) { + free(pipe); return -RIG_EINTERNAL; } @@ -143,7 +144,7 @@ ssize_t async_pipe_read(hamlib_async_pipe_t *pipe, void *buf, size_t count, LPOVERLAPPED overlapped = &pipe->read_overlapped; DWORD wait_result; int result; - ssize_t bytes_read; + ssize_t bytes_read = 0; result = ReadFile(read_handle, buf, count, NULL, overlapped); @@ -248,7 +249,7 @@ ssize_t async_pipe_write(hamlib_async_pipe_t *pipe, const unsigned char *buf, LPOVERLAPPED overlapped = &pipe->write_overlapped; DWORD wait_result; int result; - ssize_t bytes_written; + ssize_t bytes_written = 0; result = WriteFile(write_handle, buf, count, NULL, overlapped); diff --git a/lib/cJSON.c b/lib/cJSON.c index 4df0485e3..524ba4641 100644 --- a/lib/cJSON.c +++ b/lib/cJSON.c @@ -57,7 +57,6 @@ #endif #include "cJSON.h" -#include /* define our own boolean type */ #ifdef true @@ -86,8 +85,7 @@ #endif #endif -typedef struct -{ +typedef struct { const unsigned char *json; size_t position; } error; @@ -95,10 +93,10 @@ static error global_error = { NULL, 0 }; CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) { - return (const char *)(global_error.json + global_error.position); + return (const char*) (global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) { if (!cJSON_IsString(item)) { @@ -108,7 +106,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) { if (!cJSON_IsNumber(item)) { @@ -120,21 +118,19 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15) -#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -CJSON_PUBLIC(const char *) cJSON_Version(void) +CJSON_PUBLIC(const char*) cJSON_Version(void) { static char version[15]; - SNPRINTF(version, sizeof(version), "%i.%i.%i", CJSON_VERSION_MAJOR, - CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); return version; } /* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ -static int case_insensitive_strcmp(const unsigned char *string1, - const unsigned char *string2) +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) { if ((string1 == NULL) || (string2 == NULL)) { @@ -146,7 +142,7 @@ static int case_insensitive_strcmp(const unsigned char *string1, return 0; } - for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { if (*string1 == '\0') { @@ -166,15 +162,15 @@ typedef struct internal_hooks #if defined(_MSC_VER) /* work around MSVC error C2322: '...' address of dllimport '...' is not static */ -static void *CJSON_CDECL internal_malloc(size_t size) +static void * CJSON_CDECL internal_malloc(size_t size) { - return calloc(1, size); + return malloc(size); } static void CJSON_CDECL internal_free(void *pointer) { free(pointer); } -static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) +static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) { return realloc(pointer, size); } @@ -189,8 +185,7 @@ static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; -static unsigned char *cJSON_strdup(const unsigned char *string, - const internal_hooks *const hooks) +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) { size_t length = 0; unsigned char *copy = NULL; @@ -200,20 +195,18 @@ static unsigned char *cJSON_strdup(const unsigned char *string, return NULL; } - length = strlen((const char *)string) + sizeof(""); - copy = (unsigned char *)hooks->allocate(length); - + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); if (copy == NULL) { return NULL; } - memcpy(copy, string, length); return copy; } -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) { if (hooks == NULL) { @@ -225,14 +218,12 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) } global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) { global_hooks.allocate = hooks->malloc_fn; } global_hooks.deallocate = free; - if (hooks->free_fn != NULL) { global_hooks.deallocate = hooks->free_fn; @@ -240,7 +231,6 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) /* use realloc only if both free and malloc are used */ global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) { global_hooks.reallocate = realloc; @@ -248,10 +238,9 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) } /* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks *const hooks) +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) { - cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); - + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); if (node) { memset(node, '\0', sizeof(cJSON)); @@ -264,26 +253,21 @@ static cJSON *cJSON_New_Item(const internal_hooks *const hooks) CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { cJSON *next = NULL; - while (item != NULL) { next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { cJSON_Delete(item->child); } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { global_hooks.deallocate(item->valuestring); } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { global_hooks.deallocate(item->string); } - global_hooks.deallocate(item); item = next; } @@ -318,8 +302,7 @@ typedef struct #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) /* Parse the input text to generate a number, and populate the result into item. */ -static cJSON_bool parse_number(cJSON *const item, - parse_buffer *const input_buffer, int input_buffer_len) +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) { double number = 0; unsigned char *after_end = NULL; @@ -335,42 +318,39 @@ static cJSON_bool parse_number(cJSON *const item, /* copy the number into a temporary buffer and replace '.' with the decimal point * of the current locale (for strtod) * This also takes care of '\0' not necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) - && can_access_at_index(input_buffer, i); i++) + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) { switch (buffer_at_offset(input_buffer)[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; - case '.': - number_c_string[i] = decimal_point; - break; + case '.': + number_c_string[i] = decimal_point; + break; - default: - goto loop_end; + default: + goto loop_end; } } - loop_end: number_c_string[i] = '\0'; - number = strtod((const char *)number_c_string, (char **)&after_end); - + number = strtod((const char*)number_c_string, (char**)&after_end); if (number_c_string == after_end) { return false; /* parse_error */ @@ -417,35 +397,28 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) return object->valuedouble = number; } -CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, - const char *valuestring) +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) { char *copy = NULL; - /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { return NULL; } - if (strlen(valuestring) <= strlen(object->valuestring)) { strcpy(object->valuestring, valuestring); return object->valuestring; } - - copy = (char *) cJSON_strdup((const unsigned char *)valuestring, &global_hooks); - + copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); if (copy == NULL) { return NULL; } - if (object->valuestring != NULL) { cJSON_free(object->valuestring); } - object->valuestring = copy; return copy; @@ -463,7 +436,7 @@ typedef struct } printbuffer; /* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char *ensure(printbuffer *const p, size_t needed) +static unsigned char* ensure(printbuffer * const p, size_t needed) { unsigned char *newbuffer = NULL; size_t newsize = 0; @@ -486,14 +459,12 @@ static unsigned char *ensure(printbuffer *const p, size_t needed) } needed += p->offset + 1; - if (needed <= p->length) { return p->buffer + p->offset; } - if (p->noalloc) - { + if (p->noalloc) { return NULL; } @@ -518,8 +489,7 @@ static unsigned char *ensure(printbuffer *const p, size_t needed) if (p->hooks.reallocate != NULL) { /* reallocate with realloc if available */ - newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); - + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); if (newbuffer == NULL) { p->hooks.deallocate(p->buffer); @@ -532,8 +502,7 @@ static unsigned char *ensure(printbuffer *const p, size_t needed) else { /* otherwise reallocate manually */ - newbuffer = (unsigned char *)p->hooks.allocate(newsize); - + newbuffer = (unsigned char*)p->hooks.allocate(newsize); if (!newbuffer) { p->hooks.deallocate(p->buffer); @@ -546,7 +515,6 @@ static unsigned char *ensure(printbuffer *const p, size_t needed) memcpy(newbuffer, p->buffer, p->offset + 1); p->hooks.deallocate(p->buffer); } - p->length = newsize; p->buffer = newbuffer; @@ -554,18 +522,16 @@ static unsigned char *ensure(printbuffer *const p, size_t needed) } /* calculate the new length of the string in a printbuffer and update the offset */ -static void update_offset(printbuffer *const buffer) +static void update_offset(printbuffer * const buffer) { const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) { return; } - buffer_pointer = buffer->buffer + buffer->offset; - buffer->offset += strlen((const char *)buffer_pointer); + buffer->offset += strlen((const char*)buffer_pointer); } /* securely comparison of floating-point variables */ @@ -576,8 +542,7 @@ static cJSON_bool compare_double(double a, double b) } /* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON *const item, - printbuffer *const output_buffer) +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) { unsigned char *output_pointer = NULL; double d = item->valuedouble; @@ -595,22 +560,22 @@ static cJSON_bool print_number(const cJSON *const item, /* This checks for NaN and Infinity */ if (isnan(d) || isinf(d)) { - SNPRINTF((char *)number_buffer, sizeof(number_buffer), "null"); - length = strlen((char *)number_buffer); + length = sprintf((char*)number_buffer, "null"); } + else if(d == (double)item->valueint) + { + length = sprintf((char*)number_buffer, "%d", item->valueint); + } else { /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ - SNPRINTF((char *)number_buffer, sizeof(number_buffer), "%1.15g", d); - length = strlen((char *)number_buffer); + length = sprintf((char*)number_buffer, "%1.15g", d); /* Check whether the original double can be recovered */ - if ((sscanf((char *)number_buffer, "%lg", &test) != 1) - || !compare_double((double)test, d)) + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) { /* If not, print with 17 decimal places of precision */ - SNPRINTF((char *)number_buffer, sizeof(number_buffer), "%1.17g", d); - length = strlen((char *)number_buffer); + length = sprintf((char*)number_buffer, "%1.17g", d); } } @@ -622,7 +587,6 @@ static cJSON_bool print_number(const cJSON *const item, /* reserve appropriate space in the output */ output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) { return false; @@ -640,7 +604,6 @@ static cJSON_bool print_number(const cJSON *const item, output_pointer[i] = number_buffer[i]; } - output_pointer[i] = '\0'; output_buffer->offset += (size_t)length; @@ -649,7 +612,7 @@ static cJSON_bool print_number(const cJSON *const item, } /* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char *const input) +static unsigned parse_hex4(const unsigned char * const input) { unsigned int h = 0; size_t i = 0; @@ -686,9 +649,7 @@ static unsigned parse_hex4(const unsigned char *const input) /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char utf16_literal_to_utf8(const unsigned char *const - input_pointer, const unsigned char *const input_end, - unsigned char **output_pointer) +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) { long unsigned int codepoint = 0; unsigned int first_code = 0; @@ -734,7 +695,6 @@ static unsigned char utf16_literal_to_utf8(const unsigned char *const /* get the second utf16 sequence */ second_code = parse_hex4(second_sequence + 2); - /* check that the code is valid */ if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { @@ -785,14 +745,12 @@ static unsigned char utf16_literal_to_utf8(const unsigned char *const } /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; - utf8_position--) + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) { /* 10xxxxxx */ (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); codepoint >>= 6; } - /* encode first byte */ if (utf8_length > 1) { @@ -812,8 +770,7 @@ fail: } /* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON *const item, - parse_buffer *const input_buffer, int input_buffer_len) +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) { const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; @@ -830,9 +787,7 @@ static cJSON_bool parse_string(cJSON *const item, /* calculate approximate size of the output (overestimate) */ size_t allocation_length = 0; size_t skipped_bytes = 0; - - while (((size_t)(input_end - input_buffer->content) < input_buffer->length) - && (*input_end != '\"')) + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) { /* is escape sequence */ if (input_end[0] == '\\') @@ -842,26 +797,19 @@ static cJSON_bool parse_string(cJSON *const item, /* prevent buffer overflow when last input character is a backslash */ goto fail; } - skipped_bytes++; input_end++; } - input_end++; } - - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) - || (*input_end != '\"')) + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) { goto fail; /* string ended unexpectedly */ } /* This is at most how much we need for the output */ - allocation_length = (size_t)(input_end - buffer_at_offset( - input_buffer)) - skipped_bytes; - output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + - sizeof("")); - + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); if (output == NULL) { goto fail; /* allocation failure */ @@ -869,7 +817,6 @@ static cJSON_bool parse_string(cJSON *const item, } output_pointer = output; - /* loop through the string literal */ while (input_pointer < input_end) { @@ -881,7 +828,6 @@ static cJSON_bool parse_string(cJSON *const item, else { unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) { goto fail; @@ -889,49 +835,40 @@ static cJSON_bool parse_string(cJSON *const item, switch (input_pointer[1]) { - case 'b': - *output_pointer++ = '\b'; - break; + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; - case 'f': - *output_pointer++ = '\f'; - break; + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; - case 'n': - *output_pointer++ = '\n'; - break; - - case 'r': - *output_pointer++ = '\r'; - break; - - case 't': - *output_pointer++ = '\t'; - break; - - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; - - /* UTF-16 literal */ - case 'u': - sequence_length = utf16_literal_to_utf8(input_pointer, input_end, - &output_pointer); - - if (sequence_length == 0) - { - /* failed to convert UTF16-literal to UTF-8 */ + default: goto fail; - } - - break; - - default: - goto fail; } - input_pointer += sequence_length; } } @@ -940,15 +877,14 @@ static cJSON_bool parse_string(cJSON *const item, *output_pointer = '\0'; item->type = cJSON_String; - item->valuestring = (char *)output; + item->valuestring = (char*)output; - input_buffer->offset = (size_t)(input_end - input_buffer->content); + input_buffer->offset = (size_t) (input_end - input_buffer->content); input_buffer->offset++; return true; fail: - if (output != NULL) { input_buffer->hooks.deallocate(output); @@ -963,8 +899,7 @@ fail: } /* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char *const input, - printbuffer *const output_buffer, int output_buffer_len) +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) { const unsigned char *input_pointer = NULL; unsigned char *output = NULL; @@ -982,13 +917,11 @@ static cJSON_bool print_string_ptr(const unsigned char *const input, if (input == NULL) { output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) { return false; } - - strcpy((char *)output, "\"\""); + strcpy((char*)output, "\"\""); return true; } @@ -998,32 +931,28 @@ static cJSON_bool print_string_ptr(const unsigned char *const input, { switch (*input_pointer) { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - - default: - if (*input_pointer < 32) - { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - - break; + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; } } - output_length = (size_t)(input_pointer - input) + escape_characters; output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) { return false; @@ -1042,13 +971,10 @@ static cJSON_bool print_string_ptr(const unsigned char *const input, output[0] = '\"'; output_pointer = output + 1; - /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; - (void)input_pointer++, output_pointer++) + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) { - if ((*input_pointer > 31) && (*input_pointer != '\"') - && (*input_pointer != '\\')) + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) { /* normal character, copy */ *output_pointer = *input_pointer; @@ -1057,46 +983,37 @@ static cJSON_bool print_string_ptr(const unsigned char *const input, { /* character needs to be escaped */ *output_pointer++ = '\\'; - switch (*input_pointer) { - case '\\': - *output_pointer = '\\'; - break; - - case '\"': - *output_pointer = '\"'; - break; - - case '\b': - *output_pointer = 'b'; - break; - - case '\f': - *output_pointer = 'f'; - break; - - case '\n': - *output_pointer = 'n'; - break; - - case '\r': - *output_pointer = 'r'; - break; - - case '\t': - *output_pointer = 't'; - break; - - default: - /* escape and print as unicode codepoint */ - sprintf((char *)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; } } } - output[output_length + 1] = '\"'; output[output_length + 2] = '\0'; @@ -1104,28 +1021,21 @@ static cJSON_bool print_string_ptr(const unsigned char *const input, } /* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON *const item, printbuffer *const p, - int p_len) +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) { - return print_string_ptr((unsigned char *)item->valuestring, p, p_len); + return print_string_ptr((unsigned char*)item->valuestring, p); } /* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer, int output_buffer_len); -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len); -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer, int output_buffer_len); -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len); -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer, int output_buffer_len); -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len); +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); /* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) { if ((buffer == NULL) || (buffer->content == NULL)) { @@ -1139,7 +1049,7 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) { - buffer->offset++; + buffer->offset++; } if (buffer->offset == buffer->length) @@ -1151,15 +1061,14 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) } /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) { if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) { return NULL; } - if (can_access_at_index(buffer, 4) - && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) { buffer->offset += 3; } @@ -1167,8 +1076,7 @@ static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) return buffer; } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, - const char **return_parse_end, cJSON_bool require_null_terminated) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) { size_t buffer_length; @@ -1180,14 +1088,11 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, /* Adding null character size due to require_null_terminated. */ buffer_length = strlen(value) + sizeof(""); - return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, - require_null_terminated); + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated); } /* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, - size_t buffer_length, const char **return_parse_end, - cJSON_bool require_null_terminated) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) { parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; cJSON *item = NULL; @@ -1201,20 +1106,18 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, goto fail; } - buffer.content = (const unsigned char *)value; + buffer.content = (const unsigned char*)value; buffer.length = buffer_length; buffer.offset = 0; buffer.hooks = global_hooks; item = cJSON_New_Item(&global_hooks); - if (item == NULL) /* memory fail */ { goto fail; } - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)), - sizeof(buffer))) + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { /* parse failure. ep is set. */ goto fail; @@ -1224,22 +1127,19 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, if (require_null_terminated) { buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') { goto fail; } } - if (return_parse_end) { - *return_parse_end = (const char *)buffer_at_offset(&buffer); + *return_parse_end = (const char*)buffer_at_offset(&buffer); } return item; fail: - if (item != NULL) { cJSON_Delete(item); @@ -1248,7 +1148,7 @@ fail: if (value != NULL) { error local_error; - local_error.json = (const unsigned char *)value; + local_error.json = (const unsigned char*)value; local_error.position = 0; if (buffer.offset < buffer.length) @@ -1262,7 +1162,7 @@ fail: if (return_parse_end != NULL) { - *return_parse_end = (const char *)local_error.json + local_error.position; + *return_parse_end = (const char*)local_error.json + local_error.position; } global_error = local_error; @@ -1277,64 +1177,54 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) return cJSON_ParseWithOpts(value, 0, 0); } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, - size_t buffer_length) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) { return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); } #define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) -static unsigned char *print(const cJSON *const item, cJSON_bool format, - const internal_hooks *const hooks) +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) { static const size_t default_buffer_size = 256; - printbuffer buffer[16]; + printbuffer buffer[1]; unsigned char *printed = NULL; memset(buffer, 0, sizeof(buffer)); /* create buffer */ - buffer->buffer = (unsigned char *) hooks->allocate(default_buffer_size); + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); buffer->length = default_buffer_size; buffer->format = format; buffer->hooks = *hooks; - if (buffer->buffer == NULL) { goto fail; } /* print the value */ - if (!print_value(item, buffer, sizeof(buffer))) + if (!print_value(item, buffer)) { goto fail; } - update_offset(buffer); /* check if reallocate is available */ if (hooks->reallocate != NULL) { - printed = (unsigned char *) hooks->reallocate(buffer->buffer, - buffer->offset + 1); - - if (printed == NULL) - { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { goto fail; } - buffer->buffer = NULL; } else /* otherwise copy the JSON over to a new buffer */ { - printed = (unsigned char *) hooks->allocate(buffer->offset + 1); - + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); if (printed == NULL) { goto fail; } - memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); printed[buffer->offset] = '\0'; /* just to be sure */ @@ -1345,7 +1235,6 @@ static unsigned char *print(const cJSON *const item, cJSON_bool format, return printed; fail: - if (buffer->buffer != NULL) { hooks->deallocate(buffer->buffer); @@ -1362,16 +1251,15 @@ fail: /* Render a cJSON item/entity/structure to text. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { - return (char *)print(item, true, &global_hooks); + return (char*)print(item, true, &global_hooks); } CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { - return (char *)print(item, false, &global_hooks); + return (char*)print(item, false, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, - cJSON_bool fmt) +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) { printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; @@ -1380,8 +1268,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, return NULL; } - p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); - + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); if (!p.buffer) { return NULL; @@ -1393,17 +1280,16 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, p.format = fmt; p.hooks = global_hooks; - if (!print_value(item, &p, sizeof(p))) + if (!print_value(item, &p)) { global_hooks.deallocate(p.buffer); return NULL; } - return (char *)p.buffer; + return (char*)p.buffer; } -CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, - const int length, const cJSON_bool format) +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) { printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; @@ -1412,19 +1298,18 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, return false; } - p.buffer = (unsigned char *)buffer; + p.buffer = (unsigned char*)buffer; p.length = (size_t)length; p.offset = 0; p.noalloc = true; p.format = format; p.hooks = global_hooks; - return print_value(item, &p, sizeof(p)); + return print_value(item, &p); } /* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer, int input_buffer_len) +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) { if ((input_buffer == NULL) || (input_buffer->content == NULL)) { @@ -1433,69 +1318,53 @@ static cJSON_bool parse_value(cJSON *const item, /* parse the different types of values */ /* null */ - if (can_read(input_buffer, 4) - && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) { item->type = cJSON_NULL; input_buffer->offset += 4; return true; } - /* false */ - if (can_read(input_buffer, 5) - && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) { item->type = cJSON_False; input_buffer->offset += 5; return true; } - /* true */ - if (can_read(input_buffer, 4) - && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) { item->type = cJSON_True; item->valueint = 1; input_buffer->offset += 4; return true; } - /* string */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '\"')) + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) { - return parse_string(item, input_buffer, input_buffer_len); + return parse_string(item, input_buffer); } - /* number */ - if (can_access_at_index(input_buffer, 0) - && ((buffer_at_offset(input_buffer)[0] == '-') - || ((buffer_at_offset(input_buffer)[0] >= '0') - && (buffer_at_offset(input_buffer)[0] <= '9')))) + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) { - return parse_number(item, input_buffer, input_buffer_len); + return parse_number(item, input_buffer); } - /* array */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '[')) + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) { - return parse_array(item, input_buffer, input_buffer_len); + return parse_array(item, input_buffer); } - /* object */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '{')) + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) { - return parse_object(item, input_buffer, input_buffer_len); + return parse_object(item, input_buffer); } return false; } /* Render a value to text. */ -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len) +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) { unsigned char *output = NULL; @@ -1506,80 +1375,70 @@ static cJSON_bool print_value(const cJSON *const item, switch ((item->type) & 0xFF) { - case cJSON_NULL: - output = ensure(output_buffer, 5); + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; - if (output == NULL) + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: { - return false; + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; } - strcpy((char *)output, "null"); - return true; + case cJSON_String: + return print_string(item, output_buffer); - case cJSON_False: - output = ensure(output_buffer, 6); + case cJSON_Array: + return print_array(item, output_buffer); - if (output == NULL) - { + case cJSON_Object: + return print_object(item, output_buffer); + + default: return false; - } - - strcpy((char *)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - - if (output == NULL) - { - return false; - } - - strcpy((char *)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: - { - size_t raw_length = 0; - - if (item->valuestring == NULL) - { - return false; - } - - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - - if (output == NULL) - { - return false; - } - - memcpy(output, item->valuestring, raw_length); - return true; - } - - case cJSON_String: - return print_string(item, output_buffer, output_buffer_len); - - case cJSON_Array: - return print_array(item, output_buffer, output_buffer_len); - - case cJSON_Object: - return print_object(item, output_buffer, output_buffer_len); - - default: - return false; } } /* Build an array from input text. */ -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer, int input_buffer_len) +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) { cJSON *head = NULL; /* head of the linked list */ cJSON *current_item = NULL; @@ -1588,7 +1447,6 @@ static cJSON_bool parse_array(cJSON *const item, { return false; /* to deeply nested */ } - input_buffer->depth++; if (buffer_at_offset(input_buffer)[0] != '[') @@ -1599,9 +1457,7 @@ static cJSON_bool parse_array(cJSON *const item, input_buffer->offset++; buffer_skip_whitespace(input_buffer); - - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ']')) + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) { /* empty array */ goto success; @@ -1616,13 +1472,11 @@ static cJSON_bool parse_array(cJSON *const item, /* step back to character in front of the first element */ input_buffer->offset--; - /* loop through the comma separated array elements */ do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { goto fail; /* allocation failure */ @@ -1645,19 +1499,15 @@ static cJSON_bool parse_array(cJSON *const item, /* parse next value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - - if (!parse_value(current_item, input_buffer, input_buffer_len)) + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } - buffer_skip_whitespace(input_buffer); } - while (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ',')); + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) - || buffer_at_offset(input_buffer)[0] != ']') + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') { goto fail; /* expected end of array */ } @@ -1665,8 +1515,7 @@ static cJSON_bool parse_array(cJSON *const item, success: input_buffer->depth--; - if (head != NULL) - { + if (head != NULL) { head->prev = current_item; } @@ -1678,7 +1527,6 @@ success: return true; fail: - if (head != NULL) { cJSON_Delete(head); @@ -1688,8 +1536,7 @@ fail: } /* Render an array to text */ -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len) +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) { unsigned char *output_pointer = NULL; size_t length = 0; @@ -1703,7 +1550,6 @@ static cJSON_bool print_array(const cJSON *const item, /* Compose the output array. */ /* opening square bracket */ output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) { return false; @@ -1715,44 +1561,35 @@ static cJSON_bool print_array(const cJSON *const item, while (current_element != NULL) { - if (!print_value(current_element, output_buffer, output_buffer_len)) + if (!print_value(current_element, output_buffer)) { return false; } - update_offset(output_buffer); - if (current_element->next) { - length = (size_t)(output_buffer->format ? 2 : 1); + length = (size_t) (output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { return false; } - *output_pointer++ = ','; - - if (output_buffer->format) + if(output_buffer->format) { *output_pointer++ = ' '; } - *output_pointer = '\0'; output_buffer->offset += length; } - current_element = current_element->next; } output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) { return false; } - *output_pointer++ = ']'; *output_pointer = '\0'; output_buffer->depth--; @@ -1761,8 +1598,7 @@ static cJSON_bool print_array(const cJSON *const item, } /* Build an object from the text. */ -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer, int input_buffer_len) +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) { cJSON *head = NULL; /* linked list head */ cJSON *current_item = NULL; @@ -1771,20 +1607,16 @@ static cJSON_bool parse_object(cJSON *const item, { return false; /* to deeply nested */ } - input_buffer->depth++; - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != '{')) + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) { goto fail; /* not an object */ } input_buffer->offset++; buffer_skip_whitespace(input_buffer); - - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '}')) + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) { goto success; /* empty object */ } @@ -1798,13 +1630,11 @@ static cJSON_bool parse_object(cJSON *const item, /* step back to character in front of the first element */ input_buffer->offset--; - /* loop through the comma separated array elements */ do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { goto fail; /* allocation failure */ @@ -1827,20 +1657,17 @@ static cJSON_bool parse_object(cJSON *const item, /* parse the name of the child */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - - if (!parse_string(current_item, input_buffer, input_buffer_len)) + if (!parse_string(current_item, input_buffer)) { goto fail; /* failed to parse name */ } - buffer_skip_whitespace(input_buffer); /* swap valuestring and string, because we parsed the name */ current_item->string = current_item->valuestring; current_item->valuestring = NULL; - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != ':')) + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) { goto fail; /* invalid object */ } @@ -1848,19 +1675,15 @@ static cJSON_bool parse_object(cJSON *const item, /* parse the value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - - if (!parse_value(current_item, input_buffer, input_buffer_len)) + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } - buffer_skip_whitespace(input_buffer); } - while (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ',')); + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != '}')) + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) { goto fail; /* expected end of object */ } @@ -1868,8 +1691,7 @@ static cJSON_bool parse_object(cJSON *const item, success: input_buffer->depth--; - if (head != NULL) - { + if (head != NULL) { head->prev = current_item; } @@ -1880,7 +1702,6 @@ success: return true; fail: - if (head != NULL) { cJSON_Delete(head); @@ -1890,8 +1711,7 @@ fail: } /* Render an object to text. */ -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer, int output_buffer_len) +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) { unsigned char *output_pointer = NULL; size_t length = 0; @@ -1903,9 +1723,8 @@ static cJSON_bool print_object(const cJSON *const item, } /* Compose the output: */ - length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { return false; @@ -1913,12 +1732,10 @@ static cJSON_bool print_object(const cJSON *const item, *output_pointer++ = '{'; output_buffer->depth++; - if (output_buffer->format) { *output_pointer++ = '\n'; } - output_buffer->offset += length; while (current_item) @@ -1927,64 +1744,51 @@ static cJSON_bool print_object(const cJSON *const item, { size_t i; output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) { return false; } - for (i = 0; i < output_buffer->depth; i++) { *output_pointer++ = '\t'; } - output_buffer->offset += output_buffer->depth; } /* print key */ - if (!print_string_ptr((unsigned char *)current_item->string, output_buffer, - output_buffer_len)) + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) { return false; } - update_offset(output_buffer); - length = (size_t)(output_buffer->format ? 2 : 1); + length = (size_t) (output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) { return false; } - *output_pointer++ = ':'; - if (output_buffer->format) { *output_pointer++ = '\t'; } - output_buffer->offset += length; /* print value */ - if (!print_value(current_item, output_buffer, output_buffer_len)) + if (!print_value(current_item, output_buffer)) { return false; } - update_offset(output_buffer); /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)( - current_item->next ? 1 : 0)); + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { return false; } - if (current_item->next) { *output_pointer++ = ','; @@ -1994,31 +1798,25 @@ static cJSON_bool print_object(const cJSON *const item, { *output_pointer++ = '\n'; } - *output_pointer = '\0'; output_buffer->offset += length; current_item = current_item->next; } - output_pointer = ensure(output_buffer, - output_buffer->format ? (output_buffer->depth + 1) : 2); - + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); if (output_pointer == NULL) { return false; } - if (output_buffer->format) { size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) { *output_pointer++ = '\t'; } } - *output_pointer++ = '}'; *output_pointer = '\0'; output_buffer->depth--; @@ -2039,7 +1837,7 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) child = array->child; - while (child != NULL) + while(child != NULL) { size++; child = child->next; @@ -2050,7 +1848,7 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) return (int)size; } -static cJSON *get_array_item(const cJSON *array, size_t index) +static cJSON* get_array_item(const cJSON *array, size_t index) { cJSON *current_child = NULL; @@ -2060,7 +1858,6 @@ static cJSON *get_array_item(const cJSON *array, size_t index) } current_child = array->child; - while ((current_child != NULL) && (index > 0)) { index--; @@ -2080,8 +1877,7 @@ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) return get_array_item(array, (size_t)index); } -static cJSON *get_object_item(const cJSON *const object, const char *const name, - const cJSON_bool case_sensitive) +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) { cJSON *current_element = NULL; @@ -2091,47 +1887,39 @@ static cJSON *get_object_item(const cJSON *const object, const char *const name, } current_element = object->child; - if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) - && (strcmp(name, current_element->string) != 0)) + while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) { current_element = current_element->next; } } else { - while ((current_element != NULL) - && (case_insensitive_strcmp((const unsigned char *)name, - (const unsigned char *)(current_element->string)) != 0)) + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) { current_element = current_element->next; } } - if ((current_element == NULL) || (current_element->string == NULL)) - { + if ((current_element == NULL) || (current_element->string == NULL)) { return NULL; } return current_element; } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *const object, - const char *const string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) { return get_object_item(object, string, false); } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *const - object, const char *const string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) { return get_object_item(object, string, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, - const char *string) +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) { return cJSON_GetObjectItem(object, string) ? 1 : 0; } @@ -2144,18 +1932,15 @@ static void suffix_object(cJSON *prev, cJSON *item) } /* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, - const internal_hooks *const hooks) +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) { cJSON *reference = NULL; - if (item == NULL) { return NULL; } reference = cJSON_New_Item(hooks); - if (reference == NULL) { return NULL; @@ -2178,7 +1963,6 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) } child = array->child; - /* * To find the last item in array quickly, we use prev in array */ @@ -2209,24 +1993,22 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) } #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic push + #pragma GCC diagnostic push #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" #endif /* helper function to cast away const */ -static void *cast_away_const(const void *string) +static void* cast_away_const(const void* string) { - return (void *)string; + return (void*)string; } #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif -static cJSON_bool add_item_to_object(cJSON *const object, - const char *const string, cJSON *const item, const internal_hooks *const hooks, - const cJSON_bool constant_key) +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) { char *new_key = NULL; int new_type = cJSON_Invalid; @@ -2238,13 +2020,12 @@ static cJSON_bool add_item_to_object(cJSON *const object, if (constant_key) { - new_key = (char *)cast_away_const(string); + new_key = (char*)cast_away_const(string); new_type = item->type | cJSON_StringIsConst; } else { - new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); - + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); if (new_key == NULL) { return false; @@ -2264,21 +2045,18 @@ static cJSON_bool add_item_to_object(cJSON *const object, return add_item_to_array(object, item); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, - const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, false); } /* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, - const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, - cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { if (array == NULL) { @@ -2288,23 +2066,19 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, return add_item_to_array(array, create_reference(item, &global_hooks)); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, - const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { if ((object == NULL) || (string == NULL)) { return false; } - return add_item_to_object(object, string, create_reference(item, &global_hooks), - &global_hooks, false); + return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); } -CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, - const char *const name) +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) { cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) { return null; @@ -2314,11 +2088,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, - const char *const name) +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) { cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) { return true_item; @@ -2328,11 +2100,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, - const char *const name) +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) { cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) { return false_item; @@ -2342,11 +2112,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, - const char *const name, const cJSON_bool boolean) +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) { cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { return bool_item; @@ -2356,11 +2124,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, - const char *const name, const double number) +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) { cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) { return number_item; @@ -2370,11 +2136,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddStringToObject(cJSON *const object, - const char *const name, const char *const string) +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) { cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) { return string_item; @@ -2384,11 +2148,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddStringToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, - const char *const name, const char *const raw) +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) { cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { return raw_item; @@ -2398,11 +2160,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, - const char *const name) +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) { cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) { return object_item; @@ -2412,11 +2172,9 @@ CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, - const char *const name) +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) { cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) { return array; @@ -2426,8 +2184,7 @@ CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, - cJSON *const item) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) { if ((parent == NULL) || (item == NULL)) { @@ -2439,7 +2196,6 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, /* not the first element */ item->prev->next = item->next; } - if (item->next != NULL) { /* not the last element */ @@ -2479,16 +2235,14 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) cJSON_Delete(cJSON_DetachItemFromArray(array, which)); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, - const char *string) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) { cJSON *to_detach = cJSON_GetObjectItem(object, string); return cJSON_DetachItemViaPointer(object, to_detach); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, - const char *string) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) { cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); @@ -2500,15 +2254,13 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) cJSON_Delete(cJSON_DetachItemFromObject(object, string)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, - const char *string) +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) { cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); } /* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, - cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) { cJSON *after_inserted = NULL; @@ -2518,7 +2270,6 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, } after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) { return add_item_to_array(array, newitem); @@ -2527,7 +2278,6 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, newitem->next = after_inserted; newitem->prev = after_inserted->prev; after_inserted->prev = newitem; - if (after_inserted == array->child) { array->child = newitem; @@ -2536,12 +2286,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, { newitem->prev->next = newitem; } - return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, - cJSON *const item, cJSON *replacement) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) { if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { @@ -2560,27 +2308,23 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, { replacement->next->prev = replacement; } - if (parent->child == item) { if (parent->child->prev == parent->child) { replacement->prev = replacement; } - parent->child = replacement; } else - { - /* - * To find the last item in array quickly, we use prev in array. - * We can't modify the last item's next pointer where this item was the parent's child - */ + { /* + * To find the last item in array quickly, we use prev in array. + * We can't modify the last item's next pointer where this item was the parent's child + */ if (replacement->prev != NULL) { replacement->prev->next = replacement; } - if (replacement->next == NULL) { parent->child->prev = replacement; @@ -2594,20 +2338,17 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, - cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) { if (which < 0) { return false; } - return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), - newitem); + return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); } -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, - cJSON *replacement, cJSON_bool case_sensitive) +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) { if ((replacement == NULL) || (string == NULL)) { @@ -2619,23 +2360,23 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, { cJSON_free(replacement->string); } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if (replacement->string == NULL) + { + return false; + } - replacement->string = (char *)cJSON_strdup((const unsigned char *)string, - &global_hooks); replacement->type &= ~cJSON_StringIsConst; - return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, - case_sensitive), replacement); + return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, - const char *string, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, - const char *string, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, true); } @@ -2644,8 +2385,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_NULL; } @@ -2656,8 +2396,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_True; } @@ -2668,8 +2407,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_False; } @@ -2680,8 +2418,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = boolean ? cJSON_True : cJSON_False; } @@ -2692,8 +2429,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_Number; item->valuedouble = num; @@ -2719,14 +2455,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_String; - item->valuestring = (char *)cJSON_strdup((const unsigned char *)string, - &global_hooks); - - if (!item->valuestring) + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2739,11 +2472,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char *)cast_away_const(string); + item->valuestring = (char*)cast_away_const(string); } return item; @@ -2752,24 +2484,19 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item != NULL) - { + if (item != NULL) { item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); + item->child = (cJSON*)cast_away_const(child); } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item != NULL) - { + if (item != NULL) { item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); + item->child = (cJSON*)cast_away_const(child); } return item; @@ -2778,14 +2505,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { item->type = cJSON_Raw; - item->valuestring = (char *)cJSON_strdup((const unsigned char *)raw, - &global_hooks); - - if (!item->valuestring) + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2798,10 +2522,9 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(&global_hooks); - - if (item) + if(item) { - item->type = cJSON_Array; + item->type=cJSON_Array; } return item; @@ -2810,7 +2533,6 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { item->type = cJSON_Object; @@ -2834,17 +2556,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) a = cJSON_CreateArray(); - for (i = 0; a && (i < (size_t)count); i++) + for(i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); - if (!n) { cJSON_Delete(a); return NULL; } - - if (!i) + if(!i) { a->child = n; } @@ -2852,12 +2572,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { suffix_object(p, n); } - p = n; } - if (a && a->child) - { + if (a && a->child) { a->child->prev = n; } @@ -2878,17 +2596,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) a = cJSON_CreateArray(); - for (i = 0; a && (i < (size_t)count); i++) + for(i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber((double)numbers[i]); - - if (!n) + if(!n) { cJSON_Delete(a); return NULL; } - - if (!i) + if(!i) { a->child = n; } @@ -2896,12 +2612,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { suffix_object(p, n); } - p = n; } - if (a && a->child) - { + if (a && a->child) { a->child->prev = n; } @@ -2922,17 +2636,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) a = cJSON_CreateArray(); - for (i = 0; a && (i < (size_t)count); i++) + for(i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); - - if (!n) + if(!n) { cJSON_Delete(a); return NULL; } - - if (!i) + if(!i) { a->child = n; } @@ -2940,20 +2652,17 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) { suffix_object(p, n); } - p = n; } - if (a && a->child) - { + if (a && a->child) { a->child->prev = n; } return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, - int count) +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) { size_t i = 0; cJSON *n = NULL; @@ -2970,27 +2679,23 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateString(strings[i]); - - if (!n) + if(!n) { cJSON_Delete(a); return NULL; } - - if (!i) + if(!i) { a->child = n; } else { - suffix_object(p, n); + suffix_object(p,n); } - p = n; } - if (a && a->child) - { + if (a && a->child) { a->child->prev = n; } @@ -3010,61 +2715,46 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { goto fail; } - /* Create new item */ newitem = cJSON_New_Item(&global_hooks); - if (!newitem) { goto fail; } - /* Copy over all vars */ newitem->type = item->type & (~cJSON_IsReference); newitem->valueint = item->valueint; newitem->valuedouble = item->valuedouble; - if (item->valuestring) { - newitem->valuestring = (char *)cJSON_strdup((unsigned char *)item->valuestring, - &global_hooks); - + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); if (!newitem->valuestring) { goto fail; } } - if (item->string) { - newitem->string = (item->type & cJSON_StringIsConst) ? item->string : - (char *)cJSON_strdup((unsigned char *)item->string, &global_hooks); - + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); if (!newitem->string) { goto fail; } } - /* If non-recursive, then we're done! */ if (!recurse) { return newitem; } - /* Walk the ->next chain for the child. */ child = item->child; - while (child != NULL) { - newchild = cJSON_Duplicate(child, - true); /* Duplicate (with recurse) each item in the ->next chain */ - + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ if (!newchild) { goto fail; } - if (next != NULL) { /* If newitem->child already set, then crosswire ->prev and ->next and move on */ @@ -3078,10 +2768,8 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) newitem->child = newchild; next = newchild; } - child = child->next; } - if (newitem && newitem->child) { newitem->child->prev = newchild; @@ -3090,7 +2778,6 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) return newitem; fail: - if (newitem != NULL) { cJSON_Delete(newitem); @@ -3105,8 +2792,7 @@ static void skip_oneline_comment(char **input) for (; (*input)[0] != '\0'; ++(*input)) { - if ((*input)[0] == '\n') - { + if ((*input)[0] == '\n') { *input += static_strlen("\n"); return; } @@ -3127,26 +2813,21 @@ static void skip_multiline_comment(char **input) } } -static void minify_string(char **input, char **output) -{ +static void minify_string(char **input, char **output) { (*output)[0] = (*input)[0]; *input += static_strlen("\""); *output += static_strlen("\""); - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) - { + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { (*output)[0] = (*input)[0]; - if ((*input)[0] == '\"') - { + if ((*input)[0] == '\"') { (*output)[0] = '\"'; *input += static_strlen("\""); *output += static_strlen("\""); return; - } - else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) - { + } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { (*output)[1] = (*input)[1]; *input += static_strlen("\""); *output += static_strlen("\""); @@ -3167,37 +2848,34 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) { switch (json[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - json++; - break; - - case '/': - if (json[1] == '/') - { - skip_oneline_comment(&json); - } - else if (json[1] == '*') - { - skip_multiline_comment(&json); - } - else - { + case ' ': + case '\t': + case '\r': + case '\n': json++; - } + break; - break; + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } else { + json++; + } + break; - case '\"': - minify_string(&json, (char **)&into); - break; + case '\"': + minify_string(&json, (char**)&into); + break; - default: - into[0] = json[0]; - json++; - into++; + default: + into[0] = json[0]; + json++; + into++; } } @@ -3205,7 +2883,7 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) *into = '\0'; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) { if (item == NULL) { @@ -3215,7 +2893,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) return (item->type & 0xFF) == cJSON_Invalid; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) { if (item == NULL) { @@ -3225,7 +2903,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) return (item->type & 0xFF) == cJSON_False; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) { if (item == NULL) { @@ -3236,7 +2914,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) } -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) { if (item == NULL) { @@ -3245,7 +2923,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) return (item->type & (cJSON_True | cJSON_False)) != 0; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) { if (item == NULL) { @@ -3255,7 +2933,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) return (item->type & 0xFF) == cJSON_NULL; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) { if (item == NULL) { @@ -3265,7 +2943,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) return (item->type & 0xFF) == cJSON_Number; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) { if (item == NULL) { @@ -3275,7 +2953,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) return (item->type & 0xFF) == cJSON_String; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) { if (item == NULL) { @@ -3285,7 +2963,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) return (item->type & 0xFF) == cJSON_Array; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) { if (item == NULL) { @@ -3295,7 +2973,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) return (item->type & 0xFF) == cJSON_Object; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) { if (item == NULL) { @@ -3305,8 +2983,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) return (item->type & 0xFF) == cJSON_Raw; } -CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, - const cJSON *const b, const cJSON_bool case_sensitive) +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) { if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { @@ -3316,18 +2993,18 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, /* check if type is valid */ switch (a->type & 0xFF) { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; - default: - return false; + default: + return false; } /* identical objects are equal */ @@ -3338,101 +3015,96 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, switch (a->type & 0xFF) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; - case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + return true; } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) + case cJSON_Object: { - return false; - } + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } - if (strcmp(a->valuestring, b->valuestring) == 0) - { return true; } - return false; - - case cJSON_Array: - { - cJSON *a_element = a->child; - cJSON *b_element = b->child; - - for (; (a_element != NULL) && (b_element != NULL);) - { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - - a_element = a_element->next; - b_element = b_element->next; - } - - /* one of the arrays is longer than the other */ - if (a_element != b_element) - { + default: return false; - } - - return true; - } - - case cJSON_Object: - { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) - { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = get_object_item(b, a_element->string, case_sensitive); - - if (b_element == NULL) - { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a subset of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) - { - a_element = get_object_item(a, b_element->string, case_sensitive); - - if (a_element == NULL) - { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) - { - return false; - } - } - - return true; - } - - default: - return false; } } diff --git a/lib/cJSON.h b/lib/cJSON.h index 90c6edb0e..95a9cf69d 100644 --- a/lib/cJSON.h +++ b/lib/cJSON.h @@ -124,9 +124,9 @@ typedef struct cJSON typedef struct cJSON_Hooks { - /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void (CJSON_CDECL *free_fn)(void *ptr); + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); } cJSON_Hooks; typedef int cJSON_bool; @@ -255,7 +255,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. - * The input pointer json cannot point to a read-only address area, such as a string constant, + * The input pointer json cannot point to a read-only address area, such as a string constant, * but should point to a readable and writable address area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); @@ -279,6 +279,13 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); +/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/ +#define cJSON_SetBoolValue(object, boolValue) ( \ + (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \ + (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \ + cJSON_Invalid\ +) + /* Macro for iterating over an array or object */ #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) diff --git a/rigs/adat/adat.c b/rigs/adat/adat.c index bec905be1..1c9ad95d5 100644 --- a/rigs/adat/adat.c +++ b/rigs/adat/adat.c @@ -1486,7 +1486,7 @@ int adat_get_single_cmd_result(RIG *pRig) { int nBufLength = 0; - if (*pcPos == '\0') // Adjust for 00 byte at beginning ... + if (*pcPos == 0) // Adjust for 00 byte at beginning ... { pcPos++; // No, please don't ask me why this happens ... ;-) } diff --git a/rigs/alinco/dx77.c b/rigs/alinco/dx77.c index 870bc83be..c75e8a7cf 100644 --- a/rigs/alinco/dx77.c +++ b/rigs/alinco/dx77.c @@ -334,7 +334,7 @@ int dx77_transaction(RIG *rig, return retval; } - if (!(data && data_len)) + if (((data == NULL) && (data_len > 0)) || ((data != NULL) && (data_len == 0))) { rig_debug(RIG_DEBUG_ERR, "%s: data and datalen not both NULL??\n", __func__); return -RIG_EINTERNAL; @@ -1013,11 +1013,11 @@ int dx77_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { lvl = 31; } - else if (val.i >= 6 && val.i < 20) + else if (val.i < 20) { lvl = val.i + 25; } - else if (val.i >= 20 && val.i <= 50) + else if (val.i <= 50) { lvl = val.i - 20; } diff --git a/rigs/alinco/dxsr8.c b/rigs/alinco/dxsr8.c index 6cab2e78c..9b28c5a3b 100644 --- a/rigs/alinco/dxsr8.c +++ b/rigs/alinco/dxsr8.c @@ -368,7 +368,7 @@ int dxsr8_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } /* extract RX freq */ - retval = num_sscanf(freqbuf, "%"SCNfreq, freq); + num_sscanf(freqbuf, "%"SCNfreq, freq); return RIG_OK; } @@ -472,6 +472,12 @@ int dxsr8_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) filter = 0; // avoid compiler warnings of being possibly uninitialized retval = dxsr8_read_num(rig, AL "~RR_NAR" EOM, &filter); + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: dxsr8_read_num:%s\n", __func__, rigerror(retval)); + return retval; + } + if (filter == 0) { *width = rig_passband_wide(rig, *mode); diff --git a/rigs/aor/aor.c b/rigs/aor/aor.c index a8bf062ff..8cc1b5ad5 100644 --- a/rigs/aor/aor.c +++ b/rigs/aor/aor.c @@ -540,7 +540,7 @@ int parse8k_aor_mode(RIG *rig, char aormode, char aorwidth, rmode_t *mode, int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { struct aor_priv_caps *priv = (struct aor_priv_caps *)rig->caps->priv; - char ackbuf[BUFSZ], ackbuf2[BUFSZ]; + char ackbuf[BUFSZ]; char *mdp, *mdp2; int ack_len, ack2_len, retval; @@ -568,6 +568,7 @@ int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if (rig->caps->rig_model == RIG_MODEL_AR5000 || rig->caps->rig_model == RIG_MODEL_AR5000A) { + char ackbuf2[BUFSZ]; retval = aor_transaction(rig, "BW" EOM, 3, ackbuf2, &ack2_len); if (retval != RIG_OK) @@ -1150,7 +1151,7 @@ static int parse_chan_line(RIG *rig, channel_t *chan, char *basep, char *tag2p; tagp = strstr(basep, "MD"); - if (!tagp && mem_caps->mode && mem_caps->width) + if (!tagp) { rig_debug(RIG_DEBUG_WARN, "%s: no MD in returned string: '%s'\n", __func__, basep); @@ -1456,7 +1457,7 @@ const char *aor_get_info(RIG *rig) return NULL; } - if (retval > 2) { idbuf[2] = '\0'; } + // never executed -- if (retval > 2) { idbuf[2] = '\0'; } retval = aor_transaction(rig, "VR" EOM, 3, frmbuf, &frm_len);