home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18276 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.4 KB  |  41 lines

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