www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/03/17/00:49:29

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=p7sSJqO/vt/N+Feg
U8C6OZTGRqNWc+me4mGaqF9C/2oSVTkBhfDQrry5M2L1aoRqngEicOokBmnvofLZ
ul8axvlE74/amm36+JpolwgL3SKn+DrVadFRR9hurq3QkqQEpdjmP2ykb1F3YJGc
1nUEyEeL+IvfvcvKez0M7nsBK/w=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=Sx1XBWu8GaOp5PpqLG34Un
bVeVg=; b=o4kKTUBKGp96SjWXuV8dRixvqNvL5zgceoBU0jXBdZRKEf2AviwhN3
Q5Je65vNbB1YqNActMxQNj+8gkbOVy1+MeLXkvR6vZIsrFILGnxrF+oLD6DnIpM+
Kfju5x+zD+lVVvkkQQjdgyKoqLr+i51eImsAyQ7aNs44GDxpVgdUY=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=H*M:online, H*F:D*t-online.de
X-HELO: mailout12.t-online.de
Subject: Re: free() and implicit conversion to a function pointer (was: Use of initialized variable in strtod.c)
References: <c5af0608-17c4-2270-dbba-c3b704c9226e AT t-online DOT de>
To: cygwin AT cygwin DOT com
From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= <HBBroeker AT t-online DOT de>
X-Forwarded-Message-Id: <c5af0608-17c4-2270-dbba-c3b704c9226e AT t-online DOT de>
Message-ID: <f76885f4-f99f-dc50-2a19-cb892a62db7e@t-online.de>
Date: Thu, 16 Mar 2017 20:24:58 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
MIME-Version: 1.0
In-Reply-To: <c5af0608-17c4-2270-dbba-c3b704c9226e@t-online.de>
X-IsSubscribed: yes

[Sorry, forgot to reply-all...]

Am 15.03.2017 um 23:48 schrieb Jeffrey Walton:

> Since Coverity is
> complaining about an implicit conversion, maybe the following will
> help to avoid the implicit part (and sidestep the finding):
>
>     if (free != NULL)
>         break;
>
> Or perhaps:
>
>     if ((void*)free != NULL)
>         break;

Even setting aside that the latter should of course have been

      if ((void*)free == NULL)
          break;

those are both worse than the original code.  (void *) is _not_ suitable 
for use with function pointers.  Neither is NULL in the general case, 
because it may very well be ((void *)0).

The reason this is wrong is that C by design treats data and functions 
as living in separate realms, i.e. its virtual machine has a Harvard 
architecture.  One of the consequences of this is that pointers to 
functions and pointers to data are incommensurable, i.e. any and all 
conversions or comparisons across this divide are wrong.  (void *) are 
compatible to all data pointers, but not to function pointers.

The only code that might actually be a slight bit better than the given

	if (! free)

would be

	if (0 != free)

The function designator `free' auto-decays into a function pointer, 
which is compared to a null pointer constant: 0.  The ! operator does 
that same thing implicitly, but is fully equivalent to it.

In other words: that message from Coverity is just _wrong_, so it 
_should_ be disabled.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019