fix JSON create value functions not actually accepting NULL as allocator arg

Thu, 09 Jan 2025 21:19:52 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 09 Jan 2025 21:19:52 +0100
changeset 1116
b381da3a9b19
parent 1115
6db21dee4929
child 1117
54df904472b0

fix JSON create value functions not actually accepting NULL as allocator arg

src/json.c file | annotate | diff | comparison | revisions
--- a/src/json.c	Wed Jan 08 20:06:37 2025 +0100
+++ b/src/json.c	Thu Jan 09 21:19:52 2025 +0100
@@ -734,6 +734,7 @@
 }
 
 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -755,6 +756,7 @@
 }
 
 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -765,6 +767,7 @@
 }
 
 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -774,6 +777,7 @@
 }
 
 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -787,6 +791,7 @@
 }
 
 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -798,6 +803,7 @@
 }
 
 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;

mercurial