From patchwork Wed Jul 28 05:09:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44494 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45A063985814 for ; Wed, 28 Jul 2021 05:10:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45A063985814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627449008; bh=vaSU3e0phnHAAi5dfZjWg6H9axCuoYStCyiPYdiZbeI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IHKtVO1COFnrIB5TqdELhY/3Kn+QSj3W0/B6mAkHTbMEx3hSPsOxgCdIpDVgfUaso wqi5d9qbn2GuukEPwGIIAwCXq+RgOD5mMnPDiiHveDLylohJBHPLjxvH3e2rSQwERt l4ajYF+2w3/7vusTQyUUFIuw92tIso6eShsg+Kmw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from quail.birch.relay.mailchannels.net (quail.birch.relay.mailchannels.net [23.83.209.151]) by sourceware.org (Postfix) with ESMTPS id E55433985835 for ; Wed, 28 Jul 2021 05:09:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E55433985835 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 BC5B3362A38; Wed, 28 Jul 2021 05:09:39 +0000 (UTC) Received: from pdx1-sub0-mail-a75.g.dreamhost.com (100-96-18-103.trex.outbound.svc.cluster.local [100.96.18.103]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5AC2E3622F3; Wed, 28 Jul 2021 05:09:39 +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.96.18.103 (trex/6.3.3); Wed, 28 Jul 2021 05:09:39 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Gusty-Drop: 12d20f022b56c95d_1627448979593_856842716 X-MC-Loop-Signature: 1627448979593:271396176 X-MC-Ingress-Time: 1627448979593 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 1EE128C383; Tue, 27 Jul 2021 22:09:39 -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 3C4188C377; Tue, 27 Jul 2021 22:09:36 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 To: libc-alpha@sourceware.org Subject: [PATCH] xmalloc: Fix warnings with gcc analyzer Date: Wed, 28 Jul 2021 10:39:28 +0530 Message-Id: <20210728050928.3873663-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H2, 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 @@ /* 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; + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free + __returns_nonnull; +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..d3203c73df 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__)