From patchwork Wed Jul 28 11:32:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1510810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=VgyWKGHe; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GZWkK6q3Qz9sWS for ; Wed, 28 Jul 2021 21:33:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7658B3990C25 for ; Wed, 28 Jul 2021 11:33:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7658B3990C25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627471991; bh=k/K137bRRFpqoPZDSZJvzr9Wlk1dI9v6iT2xAEnJwbA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VgyWKGHeHT0m5l4Tv56Mtg34odgWRsEAcDZxLJEdeOHa6KUNKihRg6x8O9jfebl4U t6sazLIgorwJl3ACU2KxnULKPqpVIi7cec4EI1wsJ/3mkdvCMgrruBqllqebV34p/b M8hhMhh4CVoZeA+ZLVPeKFaxb0VMtRfWWial4g2s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by sourceware.org (Postfix) with ESMTPS id B9B433888C76 for ; Wed, 28 Jul 2021 11:32:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9B433888C76 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 83C5D5A0B2D; Wed, 28 Jul 2021 11:32:51 +0000 (UTC) Received: from pdx1-sub0-mail-a75.g.dreamhost.com (100-96-13-112.trex-nlb.outbound.svc.cluster.local [100.96.13.112]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C50E05A0FCC; Wed, 28 Jul 2021 11:32:50 +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.13.112 (trex/6.3.3); Wed, 28 Jul 2021 11:32:51 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Imminent-Glossy: 09862fb00824ce17_1627471971036_3660625707 X-MC-Loop-Signature: 1627471971036:353199052 X-MC-Ingress-Time: 1627471971035 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 86DDF8C382; Wed, 28 Jul 2021 04:32:50 -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 E02D28C377; Wed, 28 Jul 2021 04:32:47 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 To: libc-alpha@sourceware.org Subject: [PATCH v3] xmalloc: Fix warnings with gcc analyzer Date: Wed, 28 Jul 2021 17:02:41 +0530 Message-Id: <20210728113241.4100875-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 Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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__)