From: Florian Weimer <fweimer@redhat.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v3] xmalloc: Fix warnings with gcc analyzer
Date: Wed, 28 Jul 2021 14:04:54 +0200 [thread overview]
Message-ID: <87k0la8x09.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210728113241.4100875-1-siddhesh@sourceware.org> (Siddhesh Poyarekar's message of "Wed, 28 Jul 2021 17:02:41 +0530")
* Siddhesh Poyarekar:
> Tell the compiler that xmalloc family of allocators always return
> non-NULL. xrealloc in locale/programs also always returns non-NULL,
> but that conflicts with default realloc behaviour and that of xrealloc
> in libsupport, so keep it as is for now and resolve the differences
> later.
> ---
> include/programs/xmalloc.h | 9 ++++++---
> misc/sys/cdefs.h | 10 ++++++++++
> 2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/include/programs/xmalloc.h b/include/programs/xmalloc.h
> index 33871e22ef..5dc6aac57b 100644
> --- a/include/programs/xmalloc.h
> +++ b/include/programs/xmalloc.h
> @@ -23,11 +23,14 @@
>
> /* Prototypes for a few program-wide used functions. */
> extern void *xmalloc (size_t n)
> - __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_free;
> + __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_free
> + __returns_nonnull;
> extern void *xcalloc (size_t n, size_t s)
> - __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __attr_dealloc_free;
> + __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __attr_dealloc_free
> + __returns_nonnull;
> extern void *xrealloc (void *o, size_t n)
> __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free;
> -extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free;
> +extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free
> + __returns_nonnull;
>
> #endif /* xmalloc.h */
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index 30a621ab8f..e490fc1aeb 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -330,6 +330,16 @@
> # define __nonnull(params) _GL_ATTRIBUTE_NONNULL (params)
> #endif
>
> +/* The returns_nonnull function attribute marks the return type of the function
> + as always being non-null. */
> +#ifndef __returns_nonnull
> +# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
> +# define __returns_nonnull __attribute__ ((__returns_nonnull__))
> +# else
> +# define __returns_nonnull
> +# endif
> +#endif
> +
> /* If fortification mode, we warn about unused results of certain
> function calls which can lead to problems. */
> #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
I think this version is okay, thanks.
Florian
prev parent reply other threads:[~2021-07-28 12:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 11:32 Siddhesh Poyarekar
2021-07-28 12:04 ` Florian Weimer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0la8x09.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).