From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34269 invoked by alias); 17 Mar 2017 21:04:18 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 34248 invoked by uid 89); 17 Mar 2017 21:04:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=_should_, _wrong_, Hx-languages-length:1553 X-HELO: mailout08.t-online.de Received: from mailout08.t-online.de (HELO mailout08.t-online.de) (194.25.134.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Mar 2017 21:04:16 +0000 Received: from fwd29.aul.t-online.de (fwd29.aul.t-online.de [172.20.26.134]) by mailout08.t-online.de (Postfix) with SMTP id 3045B41DECD3 for ; Fri, 17 Mar 2017 22:04:15 +0100 (CET) Received: from [192.168.2.28] (E2njH-Ze8haRW8+1G8ioIWT4ItPCQxZzLtvDbTTvEip30yQPyJsRCTJKVesOXZyQzX@[91.59.12.166]) by fwd29.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1coz2g-0ka8fo0; Fri, 17 Mar 2017 22:04:10 +0100 Subject: Fwd: Re: free() and implicit conversion to a function pointer (was: Use of initialized variable in strtod.c) References: To: newlib@sourceware.org From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= X-Forwarded-Message-Id: Message-ID: <5952177e-aff7-2653-8977-3295524fdb03@t-online.de> Date: Fri, 17 Mar 2017 21:04:00 -0000 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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00191.txt.bz2 [Sorry, forgot to reply-all, then reply-all-ed to the wrong list...] 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.