cast_away_const: Generalize for void*

This commit is contained in:
Max Bruckner 2017-11-28 02:05:02 +01:00
parent eaa90a6b74
commit 1f543f0e28

View File

@ -1892,9 +1892,9 @@ CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSO
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
/* helper function to cast away const */
static char* cast_away_const_from_string(const char* string)
static void* cast_away_const(const void* string)
{
return (char*)string;
return (void*)string;
}
#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic pop
@ -1911,7 +1911,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJ
{
global_hooks.deallocate(item->string);
}
item->string = cast_away_const_from_string(string);
item->string = (char*)cast_away_const(string);
item->type |= cJSON_StringIsConst;
cJSON_AddItemToArray(object, item);
}
@ -2204,7 +2204,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string)
if (item != NULL)
{
item->type = cJSON_String | cJSON_IsReference;
item->valuestring = cast_away_const_from_string(string);
item->valuestring = (char*)cast_away_const(string);
}
return item;