@matheusbsbs / matheus-bagliano / commits / 7d6fb370bc
Fork 0

short circuit out of a few places where we would allocate zero bytes

dietlibc versions of malloc, calloc and realloc all return NULL if they're told to allocate 0 bytes, causes the x* wrappers to die(). There are several more places where these calls could end up asking for 0 bytes, too... Maybe simply not die()-ing in the x* wrappers if 0/NULL is returned when the requested size is zero is a safer and easier way to go. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Dec 24, 2005 at 04:12 UTC 7d6fb370bc98e5d4723103dda0829b00c79da213
2 files changed +4 -1
commit.c
+3
@@ -560,6 +560,9 @@ void sort_in_topological_order(struct commit_list ** list)
560 next = next->next;
561 count++;
562 }
563 +
564 + if (!count)
565 + return;
566 /* allocate an array to help sort the list */
567 nodes = xcalloc(count, sizeof(*nodes));
568 /* link the list to the array */
diffcore-rename.c
+1 -1
@@ -282,7 +282,7 @@ void diffcore_rename(struct diff_options *options)
282 else if (detect_rename == DIFF_DETECT_COPY)
283 register_rename_src(p->one, 1);
284 }
285 - if (rename_dst_nr == 0 ||
285 + if (rename_dst_nr == 0 || rename_src_nr == 0 ||
286 (0 < rename_limit && rename_limit < rename_dst_nr))
287 goto cleanup; /* nothing to do */
288