Replace all occurences of inline with JSON_INLINE
[jansson.git] / src / value.c
index 0f2ae65..3576b81 100644 (file)
@@ -7,8 +7,7 @@
 
 #define _GNU_SOURCE
 
-#include <config.h>
-
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -19,7 +18,7 @@
 #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 +123,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);