From owner-freebsd-hackers@FreeBSD.ORG Sat Jul 1 09:07:10 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 CABF916A557 for ; Sat, 1 Jul 2006 09:07:10 +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 F251A43E85 for ; Sat, 1 Jul 2006 08:35:51 +0000 (GMT) (envelope-from matthias.andree@gmx.de) Received: (qmail invoked by alias); 01 Jul 2006 08:35:50 -0000 Received: from p509146DC.dip0.t-ipconnect.de (EHLO m2a2.dyndns.org) [80.145.70.220] by mail.gmx.net (mp030) with SMTP; 01 Jul 2006 10:35:50 +0200 X-Authenticated: #428038 Received: from localhost (localhost [127.0.0.1]) by merlin.emma.line.org (Postfix) with ESMTP id C2ACD2006C2; Sat, 1 Jul 2006 10:35:48 +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 12406-09; Sat, 1 Jul 2006 10:35:47 +0200 (CEST) Received: by merlin.emma.line.org (Postfix, from userid 500) id 0EA46200719; Sat, 1 Jul 2006 10:35:47 +0200 (CEST) From: Matthias Andree To: Pat Lashley In-Reply-To: <417C9B11412FF8C17A1AD483@Zelazny> (Pat Lashley's message of "Fri, 30 Jun 2006 12:30:13 -0400") References: <20060628181045.GA54915@curry.mchp.siemens.de> <20060629054222.GA92895@leiferikson.flosken.lan> <20060629162319.GA94921@leiferikson.flosken.lan> <20060630045937.GB97868@leiferikson.flosken.lan> <417C9B11412FF8C17A1AD483@Zelazny> X-PGP-Key: http://home.pages.de/~mandree/keys/GPGKEY.asc Date: Sat, 01 Jul 2006 10:35:47 +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 Cc: freebsd-hackers@freebsd.org, Johannes Weiner 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: Sat, 01 Jul 2006 09:07:11 -0000 Pat Lashley writes: > BUT, that said, the safest and most portable coding practice would be: > > // The C standard does not require malloc(0) to return NULL; > // but whatever it returns MUST NOT be dereferenced. > ptr = ( size == 0 ) ? NULL : malloc( size ) ; Safest (avoiding null derefence) would instead be: ptr = malloc(size ? size : 1); BTW: // is not a valid C89 comment, but a GCC-ism. -- Matthias Andree