Re: [Lit.] Buffer overruns

From: Bryan Olson (nameless_at_nowhere.org)
Date: 01/26/05


Date: Wed, 26 Jan 2005 22:15:32 GMT

infobahn wrote:

> 7.4 (ctype.h)
>
> 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.

I stand corrected. I had been going by Harbison and Steele's
/C, A Reference Manual/, know to C programmers as "H&S". H&S
apparently has this wrong. It states:

     All of the facilities described here operate properly on all
     values representable as type char or type unsigned char, and
     also for the value EOF, but are undefined for all other
     integer values unless the individual description states
     otherwise.
     [Samuel P. Harbison and Guy L. Steele, Jr., /C: A Reference
     Manual/, Fifth Edition, Prentice-Hall, 2002; Chapter 12,
     "Character Processing", page 335.]

Thus I thought a char argument to toupper (which is descibed in
chapter 12) was fine. Harbison and Steele go on to say:

     Warning: Some non-Standard implementations of C let the type
     char be signed and also support a type unsigned char, yet
     the character-handling facilities fail to operate properly
     on all values representable by type unsigned char.

That lead me to believe type char was slightly preferable to
type unsigned char.

I just checked the H&S errata, and the issue is not yet noted. I
sent it in.

I bow to your superior knowledge of the C standard. As for my
opinion of C, I'm yet again aghast at how awful it is.

-- 
--Bryan


Relevant Pages

  • Re: Use of unions
    ... that might not have the same data format, ... component last used before this assignment is the character array, ... If you use unsigned char ... treated as an intermediate byte array of type unsigned char. ...
    (comp.std.c)
  • Re: Help me understand this compiler warning.
    ... ANDing an unsigned char with an ... int /could/ produce a signed int - which, according to 6.5.7, could ... 6.3.1.8- rules for integer promotions - adds a bit of ... which is of type unsigned char. ...
    (comp.lang.c)
  • Re: Help me understand this compiler warning.
    ... | The left operand is uc, which is of type unsigned char. ... | type unsigned char from being promoted to type int. ...
    (comp.lang.c)
  • Re: Fast Image access for binarization
    ... Assuming that image has type unsigned char*, ... unsigned char *curpixel, *stop; ... bin_tbl initialization loop is fast. ...
    (sci.image.processing)
  • Re: A question about pointer of array.
    ... to cast it to unsigned anyway. ... Character handling ... representable as an unsigned char or shall equal the value ... of the macro EOF. ...
    (comp.lang.c)