From owner-cvs-all@FreeBSD.ORG Mon Apr 2 17:20:47 2007 Return-Path: X-Original-To: cvs-all@freebsd.org Delivered-To: cvs-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 66B4816A407 for ; Mon, 2 Apr 2007 17:20:47 +0000 (UTC) (envelope-from zombyfork@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by mx1.freebsd.org (Postfix) with ESMTP id 1B56313C4B0 for ; Mon, 2 Apr 2007 17:20:45 +0000 (UTC) (envelope-from zombyfork@gmail.com) Received: by ug-out-1314.google.com with SMTP id 71so1697904ugh for ; Mon, 02 Apr 2007 10:20:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=aBgKYP+/bj6MN2gK9gyr22tkJmK/sZk+mqMzuZ4+deppF7sFpcjFOJHcpBNcWCF/7Lrj3woIKvecEmCQLCK8OF3QXSe2vy/MCsfXieZlqV76W0GQq/79pdm+hvDKzC+2UHlrXHUKk+aN1aflHa/zsI1+YcQcLq4500ha2n6DkPc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=iPUA1SKscaLtXAf01jS4MDW0UzizCddDO7gvycbv9r0iYxnfZGa6aT19OOI3ZnbZXizOWzgAqYthJ1RtXLQIpj6Zwl4vZMY6uGz5Vw6ofntjbxu6AK/8SIhiuJaLPDCwTZ2wcyhkFHO2ZOx4k+vebjL9DIn6LC0Xql28NQ7Lvyg= Received: by 10.114.110.1 with SMTP id i1mr1909867wac.1175534443340; Mon, 02 Apr 2007 10:20:43 -0700 (PDT) Received: by 10.115.15.4 with HTTP; Mon, 2 Apr 2007 10:20:43 -0700 (PDT) Message-ID: <346a80220704021020o1fe14c78se8ffaad10c2b50bd@mail.gmail.com> Date: Mon, 2 Apr 2007 11:20:43 -0600 From: "Coleman Kane" To: "Wes Peters" In-Reply-To: <3B10268D-C554-4EC2-8F16-388A49982AF3@opensail.org> MIME-Version: 1.0 References: <200703282125.l2SLPuR9058727@repoman.freebsd.org> <20070402042600.GB19923@wantadilla.lemis.com> <20070402093238.dmw2rypu40sksc0o@webmail.leidinger.net> <200704020821.15298.jhb@freebsd.org> <3B10268D-C554-4EC2-8F16-388A49982AF3@opensail.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: src-committers@freebsd.org, John Baldwin , cvs-src@freebsd.org, cvs-all@freebsd.org, Greg 'groggy' Lehey , Alexander Leidinger Subject: Re: Giving in to Coverity (was: cvs commit: src/sys/netgraph/bluetooth/l2cap ng_l2cap_cmds.c) X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: cokane@cokane.org List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Apr 2007 17:20:47 -0000 On 4/2/07, Wes Peters wrote: > > > On Apr 2, 2007, at 5:21 AM, John Baldwin wrote: > > > On Monday 02 April 2007 03:32:38 am Alexander Leidinger wrote: > >> Quoting Greg 'groggy' Lehey (from Mon, 2 Apr 2007 > >> 13:56:00 +0930): > >> > >>> On Thursday, 29 March 2007 at 13:36:31 +0200, Alexander Leidinger > >>> wrote: > >>>> Quoting Andrew Thompson (from Thu, 29 Mar > >>>> 2007 > >>>> 13:52:12 +1200): > >>>> > >>>>> On Thu, Mar 29, 2007 at 10:58:34AM +0930, Greg 'groggy' Lehey > >>>>> wrote: > >>>>>> On Wednesday, 28 March 2007 at 21:25:56 +0000, Maksim > >>>>>> Yevmenkin wrote: > >>>>>>> emax 2007-03-28 21:25:56 UTC > >>>>>>> > >>>>>>> FreeBSD src repository > >>>>>>> > >>>>>>> Modified files: > >>>>>>> sys/netgraph/bluetooth/l2cap ng_l2cap_cmds.c > >>>>>>> Log: > >>>>>>> Try to silence Coverity by adding (void) in front of > >>>>>>> function call. > >>>>>>> Also add a comment, explaining why return value is not being > > checked. > >>>>>> > >>>>>> I hope Coverity isn't going to force us to add unnecessary > >>>>>> casts to > >>>>>> function calls. > >>>>> > >>>>> Well no, you can always silence Coverity by just marking it as > >>>>> a false > >>>>> bug. > >>>> > >>>> Maxim and me discussed this briefly before this commit. > >>>> > >>>> ... > >>>> > >>>> The cast does not obfuscate the code, doesn't make it harder to > >>>> read ... > >>> > >>> I've dropped the rest of your argumentation, because I don't > >>> disagree > >>> with it, but I do think that unnecessary casts cause (minor) > >>> obfuscation and make it (fractionally) more difficult to read. > >>> > >>> My concern is that we shouldn't compromise our style because of bugs > >>> in program checkers. I understand that there are alternatives, like > >>> flagging it for Coverity as "OK", and I'd expect that to be the > >>> preferable solution. But I'm not the guardian of style, so I'll let > >>> others decide on this if they care. > >> > >> There are several cases where Coverity gets something wrong (e.g. the > >> use of TAILQ). I did mark those as invalid in Coverity (until either > >> we get a new version of Coverity which understands this, or someone > >> writes a model of the TAILQ stuff for Coverity, or until someone > >> tells > >> me to mark them as false positives). I did this because I don't know > >> how to fix this in our code _and_ I see no benefit in fixing this in > >> our code just to make Coverity not moan. For the void cast we are > >> talking about I see a benefit. Coverity can count this as "the return > >> value of this function is checked". As such a report is only > >> generated > >> if a specific percentage of the use of a function is handled this > >> way, > >> it is important if we want to get reports for this. And we want to > >> get > >> reports for functions where the return value typically has to be > >> checked. > > > > There is previous history of casting a function's return value to > > (void) to > > please lint(1). Just look for '(void)printf' :) Coverity at least is > > smarter than lint as it doesn't warn about printf not being checked. > > Void casts are a valuable tool, they tell the next poor dumb > programmer who comes along "I know this returns a value but I'm too > lazy or stupid to check it." I find I often get bitten by these, in > my own code and in others. > > I mean, it's not like printf can overflow your buffer or anything, is > it? > > -- > Where am I, and what am I doing in this handbasket? > Wes Peters > wes@softweyr.com It's not so much that as it is common for a programmer to "forget" that useful return values are produced by many functions that are typically called in a fashion consistent with a void return type. They help to inform the others that are working on it that the called function does, in fact, return a value, and that this value may be helpful in debugging problems with the call or even it might be applicable to code modification being done by a second (or third) person on the project. While printf, fprintf, etc... are all simple examples to many of us, there are likely many cases where a vendor-specific function may return a value, but be called as a void. Later on, after some turn-over in staffing, a new developer inherits the code and must "learn" from it. Forcing hints like these make that job just that much easier. In addition, I have found myself in many cases where I should have checked a return value, but due to laziness I decided to add "that part" later. Of course, later came along and something else came up which caused me to forget this.... when said function call did not get the data it was expecting, errors were silently ignored and "magical" stuff began to happen. -- Coleman Kane