Browse Source

utarray_str_cpy: Remove strdup; utarray_oom() if strdup fails.

Fixes #250, #216, #184.
Arthur O'Dwyer 2 năm trước cách đây
mục cha
commit
85bf75ab71
1 tập tin đã thay đổi với 10 bổ sung1 xóa
  1. 10 1
      src/utarray.h

+ 10 - 1
src/utarray.h

@@ -234,7 +234,16 @@ typedef struct {
 static void utarray_str_cpy(void *dst, const void *src) {
   char *const *srcc = (char *const *)src;
   char **dstc = (char**)dst;
-  *dstc = (*srcc == NULL) ? NULL : strdup(*srcc);
+  if (*srcc == NULL) {
+    *dstc = NULL;
+  } else {
+    *dstc = (char*)malloc(strlen(*srcc) + 1);
+    if (*dstc == NULL) {
+      utarray_oom();
+    } else {
+      strcpy(*dstc, *srcc);
+    }
+  }
 }
 static void utarray_str_dtor(void *elt) {
   char **eltc = (char**)elt;