1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-06-15 23:35:50 +00:00

7 Commits

Author SHA1 Message Date
Paul Eggert e94aad0ca4 safe-alloc: make obsolete and remove REALLOC_N
Problem reported by Vivien Kraus in:
https://lists.gnu.org/r/bug-gnulib/2025-07/msg00073.html
This module never caught on.
* lib/safe-alloc.h (REALLOC_N): Remove.
* modules/safe-alloc: Now obsolete.
* tests/test-safe-alloc.c (main): Remove REALLOC_N test.
2025-07-13 00:49:59 -07:00
Bruno Haible 90cffddad5 Use the 'extern-inline' module explicitly where needed.
* modules/fdutimensat (Depends-on): Add extern-inline.
* modules/file-has-acl (Depends-on): Likewise.
* modules/hamt (Depends-on): Likewise.
* modules/relocatable-prog-wrapper (Depends-on): Likewise.
* modules/safe-alloc (Depends-on): Likewise.
* modules/string-desc (Depends-on): Likewise.
* modules/string-desc-quotearg (Depends-on): Likewise.
* modules/xstring-desc (Depends-on): Likewise.
* modules/xvasprintf (Depends-on): Likewise.
2023-04-03 20:17:34 +02:00
Paul Eggert 5d5120d76b safe-alloc: fix pointer implementation
The old implementation assumed that all pointers use the same
internal representation, but the C standard doesn’t guarantee
this.  Use void * (pointer) not void ** (pointer-to-pointer) for
the internal functions’ API.  The internal functions now return
NULL if and only if they failed, and the macros translate that
into -1 or 0 to satisfy the existing API.
* doc/safe-alloc.texi (Safe Allocation Macros): Mention overflow.
* lib/safe-alloc.c: Major rewrite.  Now this simply
defines SAFE_ALLOC_INLINE and includes safe-alloc.h.
* lib/safe-alloc.h: Include stddef.h, not stdlib.h.
(SAFE_ALLOC_INLINE): New macro; use Gnulib inline function style.
(safe_alloc_realloc_n): New API, which passes and returns
the pointer, and which returns NULL if and only if failure occurs.
(safe_alloc_check): New function.
(ALLOC, ALLOC_N, ALLOC_N_UNINITIALIZED, REALLOC_N):
Redo using the new API for internal functions, and using calloc
which is good enough since it’s GNU-compatible now.
(FREE): Expand to an expression rather than merely to something
that needs a following ‘;’ to become a statement.
* modules/safe-alloc (Depends-on): Add calloc-gnu.
2021-04-18 20:59:52 -07:00
Paul Eggert d4e52e5e3c safe-alloc: simplify via reallocarray
* lib/safe-alloc.c: Do not include xalloc-oversized.h.
(safe_alloc_alloc_n, safe_alloc_realloc_n):
Use reallocarray to check for size or ptrdiff_t overflow.
* modules/reallocarray (License): Switch from LGPL to LGPLv2+, as
this is needed for safe-alloc and anyway is more appropriate for
this library function common with BSD.
* modules/safe-alloc (Depends-on): Depend on reallocarray
rather than xalloc-oversized.
2021-04-18 20:59:52 -07:00
Paul Eggert b8e5f9c8ae safe-alloc: use xalloc-oversized
* lib/safe-alloc.c: Include xalloc-oversized.h.
(safe_alloc_oversized): Remove.  All uses changed to xalloc_oversized.
* modules/safe-alloc (Depends-on): Add xalloc-oversized.
2016-12-15 10:19:48 -08:00
Bruno Haible ff32b57d81 safe-alloc: Move AC_LIBOBJ invocations to module description.
* m4/safe-alloc.m4 (gl_SAFE_ALLOC): Remove AC_LIBOBJ invocation.
* modules/safe-alloc (Makefile.am): Augment lib_SOURCES.
2011-06-16 00:07:35 +02:00
David Lutterkort 032310a691 New module 'safe-alloc'. 2009-02-21 11:08:37 +01:00