From: Kristoffer Haugsbakk Date: Sat, 21 Dec 2024 12:53:29 GMT Subject: Re: [PATCH 4/4] reftable/basics: return NULL on zero-sized allocations Message-ID: <1b833ccf-080d-4a92-afe2-3f469bc23dde@app.fastmail.com> In-Reply-To: <20241221-b4-pks-reftable-oom-fix-without-readers-v1-4-12db83a3267c@pks.im> On Sat, Dec 21, 2024, at 12:50, Patrick Steinhardt wrote: > In the preceding commits we have fixed a couple of issues when > allocating zero-sized objects. These issues were masked by > implementation-defined behaviour. Quoting malloc(3p): > > If size is 0, either: > > * A null pointer shall be returned and errno may be set to an > implementation-defined value, or > > * A pointer to the allocated space shall be returned. The > application shall ensure that the pointer is not used to access an > object. > > So it is perfectly valid that implementations of this function may or > may not return a NULL pointer in such a case. > > Adapt both `reftable_malloc()` and `reftable_realloc()` so that they > return NULL pointers on zero-sized allocations. This should remove any > implementation-defined behaviour in our allocators and thus allows us to > detect such platform-specific issues more easily going forward. > > Signed-off-by: Patrick Steinhardt Nice commit message.