Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 May 2005 15:39:53 +0300
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        Andre Guibert de Bruet <andy@siliconlandmark.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Trimming top's header to display width
Message-ID:  <20050513123953.GB26764@orion.daedalusnetworks.priv>
In-Reply-To: <20050513083059.W820@lexi.siliconlandmark.com>
References:  <20050512123637.GA2966@orion.daedalusnetworks.priv> <20050513083059.W820@lexi.siliconlandmark.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-05-13 08:33, Andre Guibert de Bruet <andy@siliconlandmark.com> 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 :)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050513123953.GB26764>