From owner-freebsd-current@FreeBSD.ORG Fri May 13 12:39:56 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7CB7516A4D0 for ; Fri, 13 May 2005 12:39:56 +0000 (GMT) Received: from rosebud.otenet.gr (rosebud.otenet.gr [195.170.0.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id A62B443D6D for ; Fri, 13 May 2005 12:39:55 +0000 (GMT) (envelope-from keramida@freebsd.org) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226])j4DCcLDd032028; Fri, 13 May 2005 15:38:21 +0300 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) j4DCdrcg026846; Fri, 13 May 2005 15:39:53 +0300 (EEST) (envelope-from keramida@freebsd.org) Received: (from keramida@localhost)j4DCdr3F026845; Fri, 13 May 2005 15:39:53 +0300 (EEST) (envelope-from keramida@freebsd.org) Date: Fri, 13 May 2005 15:39:53 +0300 From: Giorgos Keramidas To: Andre Guibert de Bruet Message-ID: <20050513123953.GB26764@orion.daedalusnetworks.priv> References: <20050512123637.GA2966@orion.daedalusnetworks.priv> <20050513083059.W820@lexi.siliconlandmark.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050513083059.W820@lexi.siliconlandmark.com> cc: freebsd-current@freebsd.org Subject: Re: Trimming top's header to display width X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2005 12:39:56 -0000 On 2005-05-13 08:33, Andre Guibert de Bruet wrote: > On Thu, 12 May 2005, Giorgos Keramidas wrote: > >Does the diff below look like a good way to fix this? > > > >%%% > >+char * > >+trim_header(text) > >+ > >+char *text; > >+ > >+{ > >+ char *s; > >+ int width; > >+ > >+ s = NULL; > > Setting s to NULL is useless because malloc returns either NULL on failure > or a pointer to the allocated memory segment. Setting s to NULL unconditionally means that even if the if block right below doesn't run, the pointer *WILL* be initialized to something meaningful. > > >+ width = display_width; > >+ header_length = strlen(text); > >+ if (header_length >= width) { This part won't run all the time. If it doesn't, then `s' could potentially hold garbage from the stack and the callers of trim_header() would find it very surprising that their non-NULL pointer causes a segfault in free() :-) > Other than that pet-peeve, the patch looks good to me... Cool :)