avoid asking ?alloc() for zero bytes.

Avoid asking for zero bytes when that change simplifies overall
logic.  Later we would change the wrapper to ask for 1 byte on
platforms that return NULL for zero byte request.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2005-12-26 12:34:56 -08:00
parent 7d6fb370bc
commit 7e4a2a8483
6 changed files with 39 additions and 19 deletions

6
diff.c
View File

@ -504,9 +504,9 @@ static void prepare_temp_file(const char *name,
}
if (S_ISLNK(st.st_mode)) {
int ret;
char *buf, buf_[1024];
buf = ((sizeof(buf_) < st.st_size) ?
xmalloc(st.st_size) : buf_);
char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
if (sizeof(buf) <= st.st_size)
die("symlink too long: %s", name);
ret = readlink(name, buf, st.st_size);
if (ret < 0)
die("readlink(%s)", name);