Code

avoid asking ?alloc() for zero bytes.
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index c8159183dac830bf7cba20edf480712f039d7135..bfc864d9ccd94215aae9cc899c83e9ad149c590c 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -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);