From owner-freebsd-questions@FreeBSD.ORG Tue Oct 20 03:08:43 2009 Return-Path: Delivered-To: FreeBSD-Questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 37C6F106568B for ; Tue, 20 Oct 2009 03:08:43 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id EB3C48FC14 for ; Tue, 20 Oct 2009 03:08:42 +0000 (UTC) Received: from r55.edvax.de (port-92-195-71-245.dynamic.qsc.de [92.195.71.245]) by mx01.qsc.de (Postfix) with ESMTP id 7E3CC3CA55; Tue, 20 Oct 2009 05:08:42 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id n9K38eEV001527; Tue, 20 Oct 2009 05:08:41 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 20 Oct 2009 05:08:40 +0200 From: Polytropon To: FreeBSD-Questions@freebsd.org Message-Id: <20091020050840.e452d7c1.freebsd@edvax.de> In-Reply-To: <20091019135805.GA35875@Grumpy.DynDNS.org> References: <20091019013337.GA9522@thought.org> <72213BBF-5E05-430D-BF9A-FCD2666951C6@hiwaay.net> <20091019054344.bb4822ca.freebsd@edvax.de> <20091019135805.GA35875@Grumpy.DynDNS.org> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: David Kelly Subject: Re: need C help, passing char buffer[] by-value.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Oct 2009 03:08:43 -0000 On Mon, 19 Oct 2009 08:58:05 -0500, David Kelly wrote: > On Mon, Oct 19, 2009 at 05:43:44AM +0200, Polytropon wrote: > > to make sure s is not NULL, or testing for it explicitely like > > > > if(!s) > > ... error handling here ... > > You are missing my point that *s == 0 is not a good out of bounds range > check. That's correct. Test != NULL just ensures that it is not a NULL pointer. Range checking should always be applied additionally. > strlen() knows nothing about the buffer allocation. As I originally > said, testing for null (and my example tested) is not foolproof but its > better than nothing. One should *also* test for the known end of the > allocated buffer. Yes. That's why an additional length parameter is a good choice, as well as maybe checing every individual character, e. g. checking for validity BEFORE doing something with it. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...