]> granicus.if.org Git - graphviz/commitdiff
agstrdup_internal: handle allocation failures
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 2 Jul 2022 02:06:58 +0000 (19:06 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 5 Jul 2022 01:54:40 +0000 (18:54 -0700)
lib/cgraph/refstr.c

index 0bed41136117c380cb580634a1daf9f0327f16be..3921a4570965f08f8651f4600a099ea40721c511 100644 (file)
@@ -9,6 +9,7 @@
  *************************************************************************/
 
 #include <cgraph/cghdr.h>
+#include <cgraph/likely.h>
 #include <stddef.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -110,8 +111,12 @@ static char *agstrdup_internal(Agraph_t *g, const char *s, bool is_html) {
        sz = sizeof(refstr_t) + strlen(s);
        if (g)
            r = agalloc(g, sz);
-       else
+       else {
            r = malloc(sz);
+           if (UNLIKELY(sz > 0 && r == NULL)) {
+               return NULL;
+           }
+       }
        r->refcnt = 1;
        r->is_html = is_html;
        strcpy(r->store, s);