Skip to content

Commit

Permalink
short circuit out of a few places where we would allocate zero bytes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Wong authored and Junio C Hamano committed Dec 26, 2005
1 parent ac44f3e commit 7d6fb37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ void sort_in_topological_order(struct commit_list ** list)
next = next->next;
count++;
}

if (!count)
return;
/* allocate an array to help sort the list */
nodes = xcalloc(count, sizeof(*nodes));
/* link the list to the array */
Expand Down
2 changes: 1 addition & 1 deletion diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void diffcore_rename(struct diff_options *options)
else if (detect_rename == DIFF_DETECT_COPY)
register_rename_src(p->one, 1);
}
if (rename_dst_nr == 0 ||
if (rename_dst_nr == 0 || rename_src_nr == 0 ||
(0 < rename_limit && rename_limit < rename_dst_nr))
goto cleanup; /* nothing to do */

Expand Down

0 comments on commit 7d6fb37

Please sign in to comment.