Skip to content

Commit 7d6fb37

Browse files
Eric WongJunio C Hamano
authored andcommitted
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>
1 parent ac44f3e commit 7d6fb37

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

commit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ void sort_in_topological_order(struct commit_list ** list)
560560
next = next->next;
561561
count++;
562562
}
563+
564+
if (!count)
565+
return;
563566
/* allocate an array to help sort the list */
564567
nodes = xcalloc(count, sizeof(*nodes));
565568
/* link the list to the array */

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void diffcore_rename(struct diff_options *options)
282282
else if (detect_rename == DIFF_DETECT_COPY)
283283
register_rename_src(p->one, 1);
284284
}
285-
if (rename_dst_nr == 0 ||
285+
if (rename_dst_nr == 0 || rename_src_nr == 0 ||
286286
(0 < rename_limit && rename_limit < rename_dst_nr))
287287
goto cleanup; /* nothing to do */
288288

0 commit comments

Comments
 (0)