From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 07165382C419 for ; Wed, 28 Jul 2021 12:05:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07165382C419 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8-NEXNtgkvN3asqmF6nLuYrA-1; Wed, 28 Jul 2021 08:04:58 -0400 X-MC-Unique: NEXNtgkvN3asqmF6nLuYrA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6EBA51084F40; Wed, 28 Jul 2021 12:04:57 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94FA95D6A1; Wed, 28 Jul 2021 12:04:56 +0000 (UTC) From: Florian Weimer To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v3] xmalloc: Fix warnings with gcc analyzer References: <20210728113241.4100875-1-siddhesh@sourceware.org> Date: Wed, 28 Jul 2021 14:04:54 +0200 In-Reply-To: <20210728113241.4100875-1-siddhesh@sourceware.org> (Siddhesh Poyarekar's message of "Wed, 28 Jul 2021 17:02:41 +0530") Message-ID: <87k0la8x09.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2021 12:05:01 -0000 * 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