]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Don't use ssize_t for storing difference between sizes
authorOndřej Surý <ondrej@isc.org>
Thu, 5 Jun 2025 10:19:43 +0000 (12:19 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 30 Jun 2025 11:22:39 +0000 (13:22 +0200)
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.

lib/isc/mem.c

index bb2805c1b41850769d364e6cda29db3e246bdb77..e7421e012e3df789f38d60c72a94321c1cf85fe6 100644 (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);
                }