X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fvalue.c;h=89d7b71d83c3a2103d31023f56afabb5742e7a58;hb=bb5d4efb2ef9609bcd1163238bccd11a1df28095;hp=bbc43c8c9cefe21390e849b8b7be7ae2867939c4;hpb=68f2861e92e08eb5e2af51c026981bc1e990e1eb;p=jansson.git diff --git a/src/value.c b/src/value.c index bbc43c8..89d7b71 100644 --- a/src/value.c +++ b/src/value.c @@ -7,8 +7,7 @@ #define _GNU_SOURCE -#include - +#include #include #include @@ -16,10 +15,9 @@ #include "hashtable.h" #include "jansson_private.h" #include "utf.h" -#include "util.h" -static inline void json_init(json_t *json, json_type type) +static JSON_INLINE void json_init(json_t *json, json_type type) { json->type = type; json->refcount = 1; @@ -124,9 +122,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); @@ -725,7 +725,7 @@ static json_t *json_string_copy(json_t *string) /*** integer ***/ -json_t *json_integer(int value) +json_t *json_integer(json_int_t value) { json_integer_t *integer = malloc(sizeof(json_integer_t)); if(!integer) @@ -736,7 +736,7 @@ json_t *json_integer(int value) return &integer->json; } -int json_integer_value(const json_t *json) +json_int_t json_integer_value(const json_t *json) { if(!json_is_integer(json)) return 0; @@ -744,7 +744,7 @@ int json_integer_value(const json_t *json) return json_to_integer(json)->value; } -int json_integer_set(json_t *json, int value) +int json_integer_set(json_t *json, json_int_t value) { if(!json_is_integer(json)) return -1; @@ -834,30 +834,21 @@ double json_number_value(const json_t *json) json_t *json_true(void) { - static json_t the_true = { - .type = JSON_TRUE, - .refcount = (size_t)-1 - }; + static json_t the_true = {JSON_TRUE, (size_t)-1}; return &the_true; } json_t *json_false(void) { - static json_t the_false = { - .type = JSON_FALSE, - .refcount = (size_t)-1 - }; + static json_t the_false = {JSON_FALSE, (size_t)-1}; return &the_false; } json_t *json_null(void) { - static json_t the_null = { - .type = JSON_NULL, - .refcount = (size_t)-1 - }; + static json_t the_null = {JSON_NULL, (size_t)-1}; return &the_null; }