Don't use ssize_t for storing difference between sizes

As POSIX guarantees only that the type ssize_t shall be capable of
storing values at least in the range [-1, {SSIZE_MAX}], it can't be used
to calculate the difference between two memory sizes.  Change the logic
for junk filling to test whether the new size is larger than old size
and then use size_t as the result will be always positive.
This commit is contained in:
Ondřej Surý 2025-06-05 12:19:43 +02:00
parent 560047307d
commit f689dc2297
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41

View file

@ -339,9 +339,9 @@ mem_realloc(isc_mem_t *ctx, void *old_ptr, size_t old_size, size_t new_size,
if ((flags & ISC__MEM_ZERO) == 0 &&
(ctx->flags & ISC_MEMFLAG_FILL) != 0)
{
ssize_t diff_size = new_size - old_size;
void *diff_ptr = (uint8_t *)new_ptr + old_size;
if (diff_size > 0) {
if (new_size > old_size) {
size_t diff_size = new_size - old_size;
void *diff_ptr = (uint8_t *)new_ptr + old_size;
/* Mnemonic for "beef". */
memset(diff_ptr, 0xbe, diff_size);
}