Skip to content

Commit 13494ed

Browse files
peffgitster
authored andcommitted
correct cache_entry allocation
Most cache_entry structs are allocated by using the cache_entry_size macro, which rounds the size of the struct up to the nearest multiple of 8 bytes (presumably to avoid memory fragmentation). There is one exception: the special "conflict entry" is allocated with an empty name, and so is explicitly given just one extra byte to hold the NUL. However, later code doesn't realize that this particular struct has been allocated differently, and happily tries reading and copying it based on the ce_size macro, which assumes the 8-byte alignment. This can lead to reading uninitalized data, though since that data is simply padding, there shouldn't be any problem as a result. Still, it makes sense to hold the padding assumption so as not to surprise later maintainers. This fixes valgrind errors in t1005, t3030, t4002, and t4114. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faf1dc7 commit 13494ed

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
382382
o->merge_size = len;
383383

384384
if (!dfc)
385-
dfc = xcalloc(1, sizeof(struct cache_entry) + 1);
385+
dfc = xcalloc(1, cache_entry_size(0));
386386
o->df_conflict_entry = dfc;
387387

388388
if (len) {

0 commit comments

Comments
 (0)