Hi,

this concerns the use of the various ctype(3) functions in the
autogen code base.  I got redirected here when I tried reporting
this against tcpreplay, they include a copy of your code in their
distribution.

Now, I'm coming to this from NetBSD, and there the ctype(3) man
page has this portion of text:

CAVEATS
     The first argument of these functions is of type int, but only a very
     restricted subset of values are actually valid.  The argument must either
     be the value of the macro EOF (which has a negative value), or must be a
     non-negative value within the range representable as unsigned char.
     Passing invalid values leads to undefined behavior.

This matches up with what the "Single Unix Specification" has to
say about this as well, e.g.

  http://pubs.opengroup.org/onlinepubs/7908799/xsh/tolower.html

which says

   The tolower() function has as a domain a type int, the value
   of which is representable as an unsigned char or the value of
   EOF. If the argument has any other value, the behaviour is
   undefined.

and similarly for the other ctype functions.

This means that roughly half of the value range of a signed char
represents values which invoke undefined behaviour when supplied
directly to the ctype functions.  And ... most implementations use
"signed char" for "char".  Casting the argument type to "int" (to
comply with the function definition) is also the wrong thing to do,
for obvious reasons.

The right thing to do is to handle EOF separately (if needed), and
in the other cases cast the arguments to the ctype functions to
"unsigned char", and (probably) let the argument promotion rules
take care of the widening of the resulting value to "int".

Now, I've not tried to put together a suggestion for a diff, as
there are quite a number of uses of these functions in the code
base.  I'm just testing the waters to get a sense for how such a
change would be received.  Any comments?

Best regards,

- HÃ¥vard

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Autogen-users mailing list
Autogen-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/autogen-users

Reply via email to