svn commit: r196752 - head/lib/libc/stdtime

Dag-Erling Smørgrav des at des.no
Thu Sep 3 13:25:27 UTC 2009


Joerg Sonnenberger <joerg at britannica.bec.de> writes:
> Dag-Erling Smørgrav <des at des.no> writes:
> > @@ -65,6 +65,15 @@
> >  .It "\&031\ EM \t032\ SUB \t033\ ESC \t034\ FS \t035\ GS"
> >  .It "\&036\ RS \t037\ US \t177\ DEL"
> >  .El
> > +.Pp
> > +.Em NOTE :
> > +if the value passed to the
> > +.Fn iscntrl
> > +function is a
> > +.Vt signed char ,
> > +as is usually the case, it must be cast to an
> > +.Vt unsigned char
> > +to avoid sign-extension errors.
> >  .Sh RETURN VALUES
> >  The
> >  .Fn iscntrl
> This is actually not good enough. ISO C doesn't specify whether plain
> char is signed or unsigned.

This is FreeBSD.  Our char is signed.  On systems where it isn't (IRIX
is the only one I know of), the cast is a no-op.

> Also, isascii is the only exception to this rule, so the change for that
> is wrong.

No.  The fact that isascii() accidentally returns the correct answer
even in the absence of a cast is irrelevant.  Passing a signed char to
isascii() invokes undefined behavior.

      7.4 Character handling <ctype.h>

  1   The header <ctype.h> declares several functions useful for
      classifying and mapping characters.166) In all cases the
      argument is an int, the value of which shall be representable as
      an unsigned char or shall equal the value of the macro EOF. If
      the argument has any other value, the behavior is undefined.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the svn-src-all mailing list