]> git.ipfire.org Git - thirdparty/git.git/commit
reftable/stack: fix zero-sized allocation when there are no readers
authorPatrick Steinhardt <ps@pks.im>
Sun, 22 Dec 2024 07:24:30 +0000 (08:24 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Dec 2024 08:58:23 +0000 (00:58 -0800)
commit2d3cb4b4b5401e2fd5a40600277f424032fc72f0
treea774b7a09609d0a84700f78c39d026ac569a74cd
parent5ab83521cfe687e4295f5748f2c5d2aa7477efe5
reftable/stack: fix zero-sized allocation when there are no readers

Similar as the preceding commit, we may try to do a zero-sized
allocation when reloading a reftable stack that ain't got any tables.
It is implementation-defined whether malloc(3p) returns a NULL pointer
in that case or a zero-sized object. In case it does return a NULL
pointer though it causes us to think we have run into an out-of-memory
situation, and thus we return an error.

Fix this by only allocating arrays when they have at least one entry.

Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/stack.c