Skip to content

Commit 421b488

Browse files
peffgitster
authored andcommitted
pack-objects: avoid reading uninitalized data
In the main loop of find_deltas, we do: struct object_entry *entry = *list++; ... if (!*list_size) ... break Because we look at and increment *list _before_ the check of list_size, in the very last iteration of the loop we will look at uninitialized data, and increment the pointer beyond one past the end of the allocated space. Since we don't actually do anything with the data until after the check, this is not a problem in practice. But since it technically violates the C standard, and because it provokes a spurious valgrind warning, let's just move the initialization of entry to a safe place. This fixes valgrind errors in t5300, t5301, t5302, t303, and t9400. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13494ed commit 421b488

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

builtin-pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
13771377
memset(array, 0, array_size);
13781378

13791379
for (;;) {
1380-
struct object_entry *entry = *list++;
1380+
struct object_entry *entry;
13811381
struct unpacked *n = array + idx;
13821382
int j, max_depth, best_base = -1;
13831383

@@ -1386,6 +1386,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
13861386
progress_unlock();
13871387
break;
13881388
}
1389+
entry = *list++;
13891390
(*list_size)--;
13901391
if (!entry->preferred_base) {
13911392
(*processed)++;

0 commit comments

Comments
 (0)