From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115382 invoked by alias); 16 Mar 2017 19:25:09 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 115073 invoked by uid 89); 16 Mar 2017 19:25:08 -0000 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 Received: from mailout12.t-online.de (HELO mailout12.t-online.de) (194.25.134.22) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Mar 2017 19:25:06 +0000 Received: from fwd24.aul.t-online.de (fwd24.aul.t-online.de [172.20.26.129]) by mailout12.t-online.de (Postfix) with SMTP id 8DD5141EF71A for ; Thu, 16 Mar 2017 20:25:04 +0100 (CET) Received: from [192.168.2.28] (EkuwwYZZohx5cWEjLfo1NRA1AJ2sabUo8xR7RHRZ+1xd8hh-mKlRdTj0Va2lCycg+Q@[91.59.13.80]) by fwd24.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1cob1A-0Bmtzk0; Thu, 16 Mar 2017 20:25:00 +0100 Subject: Re: free() and implicit conversion to a function pointer (was: Use of initialized variable in strtod.c) References: To: cygwin@cygwin.com From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= X-Forwarded-Message-Id: Message-ID: Date: Thu, 16 Mar 2017 19:25: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-03/txt/msg00175.txt.bz2 [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