diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2008-03-13 16:19:35 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-03-13 23:43:56 -0700 |
commit | 381b851c9b010147bb1fa83a013b7c8f60419026 (patch) | |
tree | ec0e5f958344a99775c2ec82e755f9c9b50caa40 /xdiff-interface.c | |
parent | 1affea4f629537fd48e3bd66de89a6f45d0fcd82 (diff) | |
download | git-381b851c9b010147bb1fa83a013b7c8f60419026.tar.gz |
merge-file: handle empty files gracefully
Earlier, it would error out while trying to read and/or writing them.
Now, calling merge-file with empty files is neither interesting nor
useful, but it is a bug that needed fixing.
Noticed by Clemens Buchacher.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'xdiff-interface.c')
-rw-r--r-- | xdiff-interface.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c index 4b8e5cca80..d8ba7e725f 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -152,8 +152,8 @@ int read_mmfile(mmfile_t *ptr, const char *filename) if ((f = fopen(filename, "rb")) == NULL) return error("Could not open %s", filename); sz = xsize_t(st.st_size); - ptr->ptr = xmalloc(sz); - if (fread(ptr->ptr, sz, 1, f) != 1) + ptr->ptr = xmalloc(sz ? sz : 1); + if (sz && fread(ptr->ptr, sz, 1, f) != 1) return error("Could not read %s", filename); fclose(f); ptr->size = sz; |