From 84237ff48e69825c94261c624eb0376d0c328139 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Mon, 6 Mar 2017 10:40:01 +0100 Subject: [PATCH] Replace sizeof('\0') with sizeof("") Because sizeof('\0') is actually sizeof(int) not sizeof(char). --- cJSON.c | 4 ++-- fuzzing/afl.c | 2 +- tests/common.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cJSON.c b/cJSON.c index 0c689c88..891cab39 100644 --- a/cJSON.c +++ b/cJSON.c @@ -628,7 +628,7 @@ static const unsigned char *parse_string(cJSON * const item, const unsigned char /* This is at most how much we need for the output */ allocation_length = (size_t) (input_end - input) - skipped_bytes; - output = (unsigned char*)hooks->allocate(allocation_length + sizeof('\0')); + output = (unsigned char*)hooks->allocate(allocation_length + sizeof("")); if (output == NULL) { goto fail; /* allocation failure */ @@ -1101,7 +1101,7 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons return false; } - raw_length = strlen(item->valuestring) + sizeof('\0'); + raw_length = strlen(item->valuestring) + sizeof(""); output = ensure(output_buffer, raw_length, hooks); if (output == NULL) { diff --git a/fuzzing/afl.c b/fuzzing/afl.c index ac4f2303..036ed14b 100644 --- a/fuzzing/afl.c +++ b/fuzzing/afl.c @@ -56,7 +56,7 @@ static char *read_file(const char *filename) } /* allocate content buffer */ - content = (char*)malloc((size_t)length + sizeof('\0')); + content = (char*)malloc((size_t)length + sizeof("")); if (content == NULL) { goto cleanup; diff --git a/tests/common.c b/tests/common.c index 3870896a..12022e11 100644 --- a/tests/common.c +++ b/tests/common.c @@ -70,7 +70,7 @@ CJSON_PUBLIC(char*) read_file(const char *filename) } /* allocate content buffer */ - content = (char*)malloc((size_t)length + sizeof('\0')); + content = (char*)malloc((size_t)length + sizeof("")); if (content == NULL) { goto cleanup;