Skip to content

Commit 0601e13

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] diff.c: locate_size_cache() fix.
This fixes two bugs. - declaration of auto variable "cmp" was preceeded by a statement, causing compilation error on real C compilers; noticed and patch given by Yoichi Yuasa. - the function's calling convention was overloading its size parameter to mean "largest possible value means do not add entry", which was a bad taste. Brought up during a discussion with Peter Baudis. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 5aa7d94 commit 0601e13

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

diff.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ static struct sha1_size_cache {
236236
static int sha1_size_cache_nr, sha1_size_cache_alloc;
237237

238238
static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
239+
int find_only,
239240
unsigned long size)
240241
{
241242
int first, last;
@@ -244,9 +245,9 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
244245
first = 0;
245246
last = sha1_size_cache_nr;
246247
while (last > first) {
247-
int next = (last + first) >> 1;
248+
int cmp, next = (last + first) >> 1;
248249
e = sha1_size_cache[next];
249-
int cmp = memcmp(e->sha1, sha1, 20);
250+
cmp = memcmp(e->sha1, sha1, 20);
250251
if (!cmp)
251252
return e;
252253
if (cmp < 0) {
@@ -256,7 +257,7 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
256257
first = next+1;
257258
}
258259
/* not found */
259-
if (size == UINT_MAX)
260+
if (find_only)
260261
return NULL;
261262
/* insert to make it at "first" */
262263
if (sha1_size_cache_alloc <= sha1_size_cache_nr) {
@@ -337,13 +338,13 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
337338
struct sha1_size_cache *e;
338339

339340
if (size_only) {
340-
e = locate_size_cache(s->sha1, UINT_MAX);
341+
e = locate_size_cache(s->sha1, 1, 0);
341342
if (e) {
342343
s->size = e->size;
343344
return 0;
344345
}
345346
if (!sha1_file_size(s->sha1, &s->size))
346-
locate_size_cache(s->sha1, s->size);
347+
locate_size_cache(s->sha1, 0, s->size);
347348
}
348349
else {
349350
s->data = read_sha1_file(s->sha1, type, &s->size);

0 commit comments

Comments
 (0)