[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 07/27] malloca: improve -fanalyzer malloc checking
From: |
Bruno Haible |
Subject: |
Re: [PATCH 07/27] malloca: improve -fanalyzer malloc checking |
Date: |
Sat, 07 Aug 2021 15:20:27 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote:
> diff --git a/lib/malloca.h b/lib/malloca.h
> index 6fa1d8b20..dbbec3f06 100644
> --- a/lib/malloca.h
> +++ b/lib/malloca.h
> @@ -65,7 +65,6 @@ extern "C" {
> # define malloca(N) \
> mmalloca (N)
> #endif
> -extern void * mmalloca (size_t n);
>
> /* Free a block of memory allocated through malloca(). */
> #if HAVE_ALLOCA
> @@ -74,6 +73,10 @@ extern void freea (void *p);
> # define freea free
> #endif
>
> +extern void *mmalloca (size_t n)
> + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (freea, 1)
> + _GL_ATTRIBUTE_ALLOC_SIZE ((1));
> +
> /* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
> It allocates an array of N objects, each with S bytes of memory,
> on the stack. N and S should be nonnegative and free of side effects.
malloca and mmalloca belong close together. I prefer to move the 'freea'
declaration, so that malloca and mmalloca are declared together.
2021-08-07 Bruno Haible <bruno@clisp.org>
malloca: Tweak last commit.
* lib/malloca.h: Keep use and declaration of mmalloca close together.
diff --git a/lib/malloca.h b/lib/malloca.h
index dbbec3f..7eb63d2 100644
--- a/lib/malloca.h
+++ b/lib/malloca.h
@@ -51,6 +51,13 @@ extern "C" {
# define safe_alloca(N) ((void) (N), NULL)
#endif
+/* Free a block of memory allocated through malloca(). */
+#if HAVE_ALLOCA
+extern void freea (void *p);
+#else
+# define freea free
+#endif
+
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
memory allocated on the stack, that must be freed using freea() before
the function returns. Upon failure, it returns NULL. */
@@ -65,14 +72,6 @@ extern "C" {
# define malloca(N) \
mmalloca (N)
#endif
-
-/* Free a block of memory allocated through malloca(). */
-#if HAVE_ALLOCA
-extern void freea (void *p);
-#else
-# define freea free
-#endif
-
extern void *mmalloca (size_t n)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (freea, 1)
_GL_ATTRIBUTE_ALLOC_SIZE ((1));
- [PATCH 01/27] backupfile: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 02/27] maint: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 03/27] dfa: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 04/27] dirname: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 05/27] exclude: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 06/27] filenamecat-lgpl: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 08/27] modechange: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 07/27] malloca: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- Re: [PATCH 07/27] malloca: improve -fanalyzer malloc checking,
Bruno Haible <=
- [PATCH 09/27] mountlist: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 10/27] pagalign_alloc: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 11/27] quotearg: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 14/27] sh-quote: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 12/27] readutmp: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 16/27] trim: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 18/27] xgethostname: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 17/27] xgetcwd: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01
- [PATCH 15/27] system-quote: improve -fanalyzer malloc checking, Paul Eggert, 2021/08/01