Explorar o código

handle null pointers: cJSONUtils_GeneratePatches

Max Bruckner %!s(int64=8) %!d(string=hai) anos
pai
achega
f0c1b896ba
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      cJSON_Utils.c

+ 8 - 1
cJSON_Utils.c

@@ -1228,7 +1228,14 @@ static void create_patches(cJSON * const patches, const unsigned char * const pa
 
 CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to)
 {
-    cJSON *patches = cJSON_CreateArray();
+    cJSON *patches = NULL;
+
+    if ((from == NULL) || (to == NULL))
+    {
+        return NULL;
+    }
+
+    patches = cJSON_CreateArray();
     create_patches(patches, (const unsigned char*)"", from, to, false);
 
     return patches;