From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 1E41E3853C32 for ; Wed, 28 Jul 2021 10:33:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E41E3853C32 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id A273D840095; Wed, 28 Jul 2021 10:33:57 +0000 (UTC) Received: from pdx1-sub0-mail-a75.g.dreamhost.com (100-105-161-168.trex.outbound.svc.cluster.local [100.105.161.168]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 497D28400B2; Wed, 28 Jul 2021 10:33:57 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a75.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.105.161.168 (trex/6.3.3); Wed, 28 Jul 2021 10:33:57 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Stop-Hysterical: 7a68a2576b12dd64_1627468437519_957073738 X-MC-Loop-Signature: 1627468437519:3739913065 X-MC-Ingress-Time: 1627468437519 Received: from pdx1-sub0-mail-a75.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTP id 001CE8C384; Wed, 28 Jul 2021 03:33:56 -0700 (PDT) Received: from rhbox.redhat.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTPSA id 5FEBD8C377; Wed, 28 Jul 2021 03:33:53 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: fweimer@redhat.com Subject: [PATCH v2] xmalloc: Fix warnings with gcc analyzer Date: Wed, 28 Jul 2021 16:03:45 +0530 Message-Id: <20210728103345.4065595-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3494.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NEUTRAL, 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 10:34:00 -0000 Tell the compiler that xmalloc family of allocators always return non-NULL. --- include/programs/xmalloc.h | 12 ++++++++---- misc/sys/cdefs.h | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/programs/xmalloc.h b/include/programs/xmalloc.h index 33871e22ef..574fb41254 100644 --- a/include/programs/xmalloc.h +++ b/include/programs/xmalloc.h @@ -23,11 +23,15 @@ =20 /* Prototypes for a few program-wide used functions. */ extern void *xmalloc (size_t n) - __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_fre= e; + __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_fre= e + __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_fre= e; -extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_= free; + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_fre= e + __returns_nonnull; +extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_= free + __returns_nonnull; =20 #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 =20 +/* The returns_nonnull function attribute marks the return type of the f= unction + 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__= ) --=20 2.31.1