Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Feb 2015 17:09:47 +0800
From:      Erich Dollansky <erichsfreebsdlist@alogt.com>
To:        John-Mark Gurney <jmg@funkthat.com>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: top, fixed buffer length in utils.c
Message-ID:  <20150204170947.17764dff@B85M-HD3-0.alogt.com>
In-Reply-To: <20150204074235.GX27103@funkthat.com>
References:  <20150201175159.7fa88d16@B85M-HD3-0.alogt.com> <20150203003307.GG27103@funkthat.com> <20150203200135.57c8c236@B85M-HD3-0.alogt.com> <20150204074235.GX27103@funkthat.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

On Tue, 3 Feb 2015 23:42:35 -0800
John-Mark Gurney <jmg@funkthat.com> wrote:

> Erich Dollansky wrote this message on Tue, Feb 03, 2015 at 20:01
> +0800:
> > On Mon, 2 Feb 2015 16:33:07 -0800
> > John-Mark Gurney <jmg@funkthat.com> wrote:
> > 
> > > Erich Dollansky wrote this message on Sun, Feb 01, 2015 at 17:51
> > > +0800:
> > > > int can be 64 bits on a amd64 machine. Why is the author of this
> > > > code so sure that we will never cross the 32 bit boundary?
> > > 
> > > Per others, int is currently 32bits on all platforms we support...
> > > 
> > > I guess adding:
> > > CTASSERT(sizeof(int) <= 4);
> > > 
> > > would help fix your concern?  at least now the expectation is
> > > codified and if it breaks, the build will break..
> > > 
> > of course. Either avoid the run-time problem or get an error message
> > and things  cannot create hidden problem.
> 
> Ok, I've generated this patch:
> Index: utils.c
> ===================================================================
> --- utils.c	(revision 277938)
> +++ utils.c	(working copy)
> @@ -58,6 +58,7 @@ char *str;
>  				 * ever convert will be 2^32-1,
> which is 10
>  				 * digits.
>  				 */
> +_Static_assert(sizeof(int) <= 4, "buffer too small for this sized
> int"); 
>  char *itoa(val)
>  
Wait, shouldn't it the other way around? It will break when sizeof
(int) is greater than 4?
> 
> I couldn't use CTASSERT because including sys/param.h and sys/systm.h
> per man page didn't work.. apparently for userland it's different and
> requires additional headers...  It appears that we define it in
> sys/cdefs.h which gets included, so this work for both clang and
> gcc...
> 
> I'll commit it soon unless someone objects...
> 
Thanks!

Erich



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