A flexible array member is unportable. Use a table of length 1
instead. This needs some adjustment to the memory allocatio, too.
typedef struct {
unsigned long serial;
- char key[];
+ char key[1];
} object_key_t;
const object_key_t *jsonp_object_iter_fullkey(void *iter);
#include <config.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
}
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);