home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: Testing competence of potential hires
- Message-ID: <1992Dec13.001549.27543@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <1g9pm5INNosg@almaak.usc.edu>
- Date: Sun, 13 Dec 92 00:15:49 GMT
- Lines: 30
-
- > void abc(char *cde)
- > {
- > for (; *cde; ++cde) *cde = toupper(*cde);
- > return cde;
- > }
- > What errors will the compiler not find?
- > - he is not checking if cde == NULL
-
- And not checking whether the chars are in range. For example, on an
- implementation with 8-bit chars that are signed and where the macro EOF
- is defined as (-1), the following causes undefined behavior even after
- the "return" statement is corrected.
-
- char x[2];
- x[0] = -2;
- x[1] = '\0';
- abc(x);
-
- As with the null pointer check, this could be considered correct if
- the specification of abc() excluded such values.
-
- In pre-ANSI C, of course, the argument of toupper() must be additionally
- be validated with islower(). One implementation of toupper(c) seen in
- pre-ANSI implentations is the simple ((c)-'a'+'A').
- --
- Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb@sq.com
- "I'm a little worried about the bug-eater," she said. "We're embedded
- in bugs, have you noticed?" -- Niven, "The Integral Trees"
-
- This article is in the public domain.
-