From: Junio C Hamano Date: Sat, 28 May 2005 19:22:38 GMT Subject: [PATCH] Diff: two fixes. Message-ID: <7vr7frrw8x.fsf_-_@assigned-by-dhcp.cox.net> In-Reply-To: <7vis13wth4.fsf_-_@assigned-by-dhcp.cox.net> The count-delta routine sometimes overcounted the copied source material which resulted in unsigned int wraparound. The latest diff-cache (uncached) fix to eliminate empty diffs from the output revealed that is_exact_match() was not careful enough, which resulted in a sanity check routine triggering when a file is added to an index. Signed-off-by: Junio C Hamano --- count-delta.c | 3 +++ diff.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/count-delta.c b/count-delta.c --- a/count-delta.c +++ b/count-delta.c @@ -88,5 +88,8 @@ unsigned long count_delta(void *delta_bu /* delete size is what was _not_ copied from source. * edit size is that and literal additions. */ + if (src_size + added_literal < copied_from_source) + /* we ended up overcounting and underflowed */ + return 0; return (src_size - copied_from_source) + added_literal; } diff --git a/diff.c b/diff.c --- a/diff.c +++ b/diff.c @@ -689,6 +689,9 @@ int is_exact_match(struct diff_filespec if (src->sha1_valid && dst->sha1_valid && !memcmp(src->sha1, dst->sha1, 20)) return 1; + /* if either is invalid they cannot match */ + if (!DIFF_FILE_VALID(src) || !DIFF_FILE_VALID(dst)) + return 0; if (diff_populate_filespec(src, 1) || diff_populate_filespec(dst, 1)) return 0; if (src->size != dst->size) ------------------------------------------------