#include <stdarg.h>
#include "json.h"
+static inline void fail_and_notify(void)
+{
+ fprintf(stderr, "Allocation of memory for json object failed, aborting.\n");
+ __builtin_abort();
+}
+
struct json_object *json_create_object(void)
{
- return calloc(1, sizeof(struct json_object));
+ void *test = calloc(1, sizeof(struct json_object));
+ if (!test)
+ fail_and_notify();
+ return test;
}
struct json_array *json_create_array(void)
{
- return calloc(1, sizeof(struct json_array));
+ void *test = calloc(1, sizeof(struct json_array));
+ if (!test)
+ fail_and_notify();
+ return test;
}
static struct json_pair *json_create_pair(const char *name, struct json_value *value)
value->parent_type = JSON_PARENT_TYPE_PAIR;
value->parent_pair = pair;
- }
+ } else
+ fail_and_notify();
+
return pair;
}
if (value) {
value->type = JSON_TYPE_INTEGER;
value->integer_number = number;
- }
+ } else
+ fail_and_notify();
+
return value;
}
if (value) {
value->type = JSON_TYPE_FLOAT;
value->float_number = number;
- }
+ } else
+ fail_and_notify();
+
return value;
}
}
p = ret = malloc(strlen(str) + escapes + 1);
+ if (!ret)
+ fail_and_notify();
+
while (*str) {
if (*str == '\\' || *str == '\"')
*p++ = '\\';
value = NULL;
}
}
+ if (!value)
+ fail_and_notify();
+
return value;
}
value->type = JSON_TYPE_OBJECT;
value->object = obj;
obj->parent = value;
- }
+ } else
+ fail_and_notify();
+
return value;
}
value->type = JSON_TYPE_ARRAY;
value->array = array;
array->parent = value;
- }
+ } else
+ fail_and_notify();
+
return value;
}