From owner-freebsd-hackers@FreeBSD.ORG Thu Jun 29 17:29:21 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C1DAB16A403 for ; Thu, 29 Jun 2006 17:29:21 +0000 (UTC) (envelope-from matthias.andree@gmx.de) Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by mx1.FreeBSD.org (Postfix) with SMTP id AC9BE43D62 for ; Thu, 29 Jun 2006 17:29:20 +0000 (GMT) (envelope-from matthias.andree@gmx.de) Received: (qmail invoked by alias); 29 Jun 2006 17:29:19 -0000 Received: from p50911D7D.dip0.t-ipconnect.de (EHLO m2a2.dyndns.org) [80.145.29.125] by mail.gmx.net (mp028) with SMTP; 29 Jun 2006 19:29:19 +0200 X-Authenticated: #428038 Received: from localhost (localhost [127.0.0.1]) by merlin.emma.line.org (Postfix) with ESMTP id 0CEE2200F1B for ; Thu, 29 Jun 2006 19:29:18 +0200 (CEST) Received: from m2a2.dyndns.org ([127.0.0.1]) by localhost (m2a2.dyndns.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29125-08 for ; Thu, 29 Jun 2006 19:29:16 +0200 (CEST) Received: by merlin.emma.line.org (Postfix, from userid 500) id 5733E200FB4; Thu, 29 Jun 2006 19:29:16 +0200 (CEST) From: Matthias Andree To: freebsd-hackers@freebsd.org In-Reply-To: <20060629162319.GA94921@leiferikson.flosken.lan> (Johannes Weiner's message of "Thu, 29 Jun 2006 18:23:19 +0200") References: <20060628181045.GA54915@curry.mchp.siemens.de> <20060629054222.GA92895@leiferikson.flosken.lan> <20060629162319.GA94921@leiferikson.flosken.lan> X-PGP-Key: http://home.pages.de/~mandree/keys/GPGKEY.asc Date: Thu, 29 Jun 2006 19:29:16 +0200 Message-ID: User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: amavisd-new at emma.line.org X-Y-GMX-Trusted: 0 Subject: Re: Return value of malloc(0) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jun 2006 17:29:21 -0000 Johannes Weiner writes: > On Thu, Jun 29, 2006 at 06:09:37PM +0200, Matthias Andree wrote: > >> The value returned from malloc(0) must not be dereferenced whatever it >> was. It was 0x800, which doesn't count as "failure". > > But this would be appropriate for catching the error: > > if ((foo = malloc(0)) == foo) > /* make noise */ > > wouldn't it? No, sir. Operator precedence: assign first, and then compare, thus the comparison will always be true (else you'd be comparing to undefined values, which isn't any better). You might as well write: foo = malloc(0); /* make noise */ There is no way to see a 0x800 return from malloc(0) as "error". -- Matthias Andree