]> granicus.if.org Git - graphviz/commitdiff
cgraph: add a 'strdup' wrapper to the allocation helpers
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 17 Mar 2022 04:21:01 +0000 (21:21 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 24 Mar 2022 15:36:53 +0000 (08:36 -0700)
lib/cgraph/alloc.h

index f5cf09d3bd317bbd94f11d1409475152a761f400..2148dedc8c52b376304d71f0571e0b32b0703286 100644 (file)
@@ -66,3 +66,14 @@ static inline void *gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb,
 
   return gv_realloc(ptr, old_nmemb * size, new_nmemb * size);
 }
+
+static inline char *gv_strdup(const char *original) {
+
+  char *copy = strdup(original);
+  if (UNLIKELY(copy == NULL)) {
+    fprintf(stderr, "out of memory\n");
+    graphviz_exit(EXIT_FAILURE);
+  }
+
+  return copy;
+}