X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=blobdiff_plain;f=src%2Fvalue.c;h=8e0cfa237a46573aeddda1c746e6cd8f72ace38f;hp=e024fdb1f72757ed2ca2500d36a13b88259243b6;hb=145032a57f7844c29f2c40415b46338ac3445207;hpb=519d52e2bb6a3840100a84e826d8d8ac91e2d3d8 diff --git a/src/value.c b/src/value.c index e024fdb..8e0cfa2 100644 --- a/src/value.c +++ b/src/value.c @@ -9,6 +9,7 @@ #include +#include #include #include @@ -124,9 +125,11 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value) } object = json_to_object(json); - k = malloc(sizeof(object_key_t) + strlen(key) + 1); - if(!k) - return -1; + /* offsetof(...) returns the size of object_key_t without the + last, flexible member. This way, the correct amount is + allocated. */ + k = malloc(offsetof(object_key_t, key) + + strlen(key) + 1); if(!k) return -1; k->serial = object->serial++; strcpy(k->key, key);