From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 dcvr.yhbt.net (Postfix) with ESMTPS id 6D08E1F8C6 for ; Wed, 28 Jul 2021 12:05:20 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 563B6382C419 for ; Wed, 28 Jul 2021 12:05:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 563B6382C419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627473919; bh=xPjnzy256aAgDaeC0cNkEj3wOwo2NjY3+OWR4DKWiqU=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=JFb9n1hs1D5z5uxssz5rRMLZuApt425cVNPg4i5qzoTvVDYjypsukfk4oaQxV0XnG HnRYRz9zdP/MqlGyLRDiicIcvBkNLDHcQycOx1rpK/W7nUakXdw4rqPXjNTBU0YL// 18PoHUo9s3AGcTGXqKnwl5SsiJYNsWkcOHsGGlmg= 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) To: Siddhesh Poyarekar 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-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: , From: Florian Weimer via Libc-alpha Reply-To: Florian Weimer Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" * 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