Sfoglia il codice sorgente

don't ignore malloc failure in cJSON_PrintBuffered

Rod Vagg 8 anni fa
parent
commit
5323f558cd
1 ha cambiato i file con 4 aggiunte e 0 eliminazioni
  1. 4 0
      cJSON.c

+ 4 - 0
cJSON.c

@@ -845,6 +845,10 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt)
 {
     printbuffer p;
     p.buffer = (char*)cJSON_malloc(prebuffer);
+    if (!p.buffer)
+    {
+        return 0;
+    }
     p.length = prebuffer;
     p.offset = 0;