From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Garzik Subject: Re: [PATCH tabled] server/server.c don't deref NULL on failed malloc Date: Thu, 23 Sep 2010 15:41:08 -0400 Message-ID: <4C9BAD54.30303@garzik.org> References: <87zkv8wwlo.fsf@meyering.net> <20100923080710.22d3f6e4@lembas.zaitcev.lan> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=ZTVwkkjXRqVDNMhjQndZy0zfO+CnIQ7s04D4rfGPmJw=; b=B8HffycxtfrytBdaLpm8uKYNPM5D8fuk+cx4bEpRJiH/VLjcW7qS7JAydlIT0xKQSY 8sVsJ92eONoQJsQQfo4wpALodFbBX9fI0x1ZH/QRQVIM/fVnmo583+R5aFyZU/E1FG8k Y1FbWsQ8DNJMNElCRPRx1oSlyu9ZmDYMKwhjs= In-Reply-To: <20100923080710.22d3f6e4@lembas.zaitcev.lan> Sender: hail-devel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: Pete Zaitcev Cc: Jim Meyering , Project Hail On 09/23/2010 10:07 AM, Pete Zaitcev wrote: > On Thu, 23 Sep 2010 13:03:15 +0200 > Jim Meyering wrote: > >> Just noticed that sometimes tabled uses this idiom: >> if (!(key = malloc(klen + 1))) >> and sometimes this: >> if ((key = malloc(klen + 1)) == NULL) >> This time I used "... == NULL". > > Er... The bang is Jeff's, which I try to follow always, but perhaps > one or two slipped due to opposing habit. IIRC pathtokey() was mine. > In fact tabled does not use assignments in conditions, dunno why > but it's a tradition. I always considered assignments in conditionals as fragile and error-prone, and try to avoid them. However, I occasionally break my own rule, such as with fgets(3) or getopt(3) loops. And, getting back on topic, I do prefer implicit rather than explicit testing for zero and non-zero... but that too is a "weak preference" where I won't complain much if somebody else does it. Typically the general rule for any codebase is "try to look like the rest of the codebase." Jeff