top, fixed buffer length in utils.c

Erich Dollansky erichsfreebsdlist at alogt.com
Thu Feb 5 01:33:51 UTC 2015


Hi,

On Wed, 4 Feb 2015 10:35:48 -0800
John-Mark Gurney <jmg at funkthat.com> wrote:

> Erich Dollansky wrote this message on Wed, Feb 04, 2015 at 17:09
> +0800:
> > Hi,
> > 
> > On Tue, 3 Feb 2015 23:42:35 -0800
> > John-Mark Gurney <jmg at funkthat.com> wrote:
> > 
> > > 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?
> 
> No, asserts trigger when the statement is false... I verified this
> by changing 4 to 2 and seeing that it failed (triggered) to compile...
> 
so, I learned something new with FreeBSD. I never use them as we have a
set of macros from a time long before these kind of macros came up and
never changed. You know, never change w winning team.

Erich


More information about the freebsd-stable mailing list