Make object_key_t portable

A flexible array member is unportable. Use a table of length 1
instead. This needs some adjustment to the memory allocatio, too.
This commit is contained in:
Petri Lehtinen 2010-08-12 21:35:19 +03:00
parent 519d52e2bb
commit 145032a57f
2 changed files with 7 additions and 4 deletions

View File

@ -53,7 +53,7 @@ typedef struct {
typedef struct { typedef struct {
unsigned long serial; unsigned long serial;
char key[]; char key[1];
} object_key_t; } object_key_t;
const object_key_t *jsonp_object_iter_fullkey(void *iter); const object_key_t *jsonp_object_iter_fullkey(void *iter);

View File

@ -9,6 +9,7 @@
#include <config.h> #include <config.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -124,9 +125,11 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value)
} }
object = json_to_object(json); object = json_to_object(json);
k = malloc(sizeof(object_key_t) + strlen(key) + 1); /* offsetof(...) returns the size of object_key_t without the
if(!k) last, flexible member. This way, the correct amount is
return -1; allocated. */
k = malloc(offsetof(object_key_t, key) +
strlen(key) + 1); if(!k) return -1;
k->serial = object->serial++; k->serial = object->serial++;
strcpy(k->key, key); strcpy(k->key, key);