bug-gnulib
[Top][All Lists]
Advanced

[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));




reply via email to

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