Skip to content

Commit

Permalink
cJSON: prevent incompatible C and header versions
Browse files Browse the repository at this point in the history
Introduces a preprocessor directive that aborts the compilation if the
version numbers in the header don't match with the numbers in the c
file.
  • Loading branch information
FSMaxB committed Feb 15, 2017
1 parent cf862d0 commit 123bb1a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const char *cJSON_GetErrorPtr(void)
return (const char*) global_ep;
}

/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 2) || (CJSON_VERSION_PATCH != 1)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif

extern const char* cJSON_Version(void)
{
static char version[15];
Expand Down

0 comments on commit 123bb1a

Please sign in to comment.