bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/3] realloc-posix: realloc (p, 0) yields nonnull


From: Bruno Haible
Subject: Re: [PATCH 1/3] realloc-posix: realloc (p, 0) yields nonnull
Date: Thu, 31 Oct 2024 21:01:25 +0100

Paul Eggert wrote:
> +      void *result = realloc (p, 1);
> +      return result ? result : p;

Unfortunately, this patch does not guarantee that errno is set to ENOMEM
upon failure. This was the original raison d'ĂȘtre of the 'realloc-posix'
module.

The first patch of this series restores the errno = ENOMEM behaviour.

Patches 0002 to 0005 add corresponding unit tests, that check errno
in the "normal" case of failure of malloc / realloc / calloc.

Since I see that these tests succeed with MSVC 14, it means that the
Windows UCRT already sets errno = ENOMEM and does not need the Gnulib
workarounds, at least since 2015. Patch 0006 deals with that.


2024-10-31  Bruno Haible  <bruno@clisp.org>

        malloc-posix, calloc-posix, realloc-posix: Optimize on MSVC.
        * m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Assume that malloc sets errno
        upon failure if UCRT is in use.

2024-10-31  Bruno Haible  <bruno@clisp.org>

        realloc-posix tests: Enhance tests.
        * tests/test-realloc-posix.c (main): Check errno also after normal
        failing realloc calls.

2024-10-31  Bruno Haible  <bruno@clisp.org>

        realloc-posix tests: Fix memory leak.
        * tests/test-realloc-posix.c (main): Don't clobber variable 'p' in
        failing call.

2024-10-31  Bruno Haible  <bruno@clisp.org>

        calloc-posix: Add tests.
        * tests/test-calloc-posix.c: New file.
        * modules/calloc-posix-tests: New file.

2024-10-31  Bruno Haible  <bruno@clisp.org>

        malloc-posix: Add tests.
        * tests/test-malloc-posix.c: New file.
        * modules/malloc-posix-tests: New file.

2024-10-31  Bruno Haible  <bruno@clisp.org>

        realloc-posix: Set errno when failing (regression 2029-10-29).
        * lib/realloc.c (rpl_realloc): When failing, with HAVE_MALLOC_POSIX not
        defined, set errno.

Attachment: 0001-realloc-posix-Set-errno-when-failing-regression-2029.patch
Description: Text Data

Attachment: 0002-malloc-posix-Add-tests.patch
Description: Text Data

Attachment: 0003-calloc-posix-Add-tests.patch
Description: Text Data

Attachment: 0004-realloc-posix-tests-Fix-memory-leak.patch
Description: Text Data

Attachment: 0005-realloc-posix-tests-Enhance-tests.patch
Description: Text Data

Attachment: 0006-malloc-posix-calloc-posix-realloc-posix-Optimize-on-.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]