home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15807 < prev    next >
Encoding:
Text File  |  1992-11-14  |  1.8 KB  |  56 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!ukma!wupost!decwrl!concert!sas!mozart.unx.sas.com!jamie
  3. From: jamie@cdevil.unx.sas.com (James Cooper)
  4. Subject: Re: Bug in SAS/C 6.0 library : strstr ()
  5. Originator: jamie@cdevil.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <Bxnw8z.CvD@unx.sas.com>
  8. Date: Fri, 13 Nov 1992 15:55:47 GMT
  9. References:  <hadig.721653082@rama>
  10. Nntp-Posting-Host: cdevil.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Keywords: strstr, SAS/C 6.0
  13. Lines: 41
  14.  
  15.  
  16. In article <hadig.721653082@rama>, hadig@rama.informatik.rwth-aachen.de (Thomas Hadig) writes:
  17. >Hi,
  18. >
  19. >i have found a bug in the SAS/C Amiga 6.0 library function strstr :
  20. >
  21. >char * strstr (char *s1, char *s2);
  22. >
  23. >strstr searches the substring s2 in the string s1 and returns the
  24. >starting address of the substring s2 in s1 or NULL if not found.
  25. >
  26. >BUG :
  27. >
  28. >If you call strstr with an empty string s1, strstr will continue the
  29. >search instead of returning NULL.
  30.  
  31. While strstr() is not an ANSI function, it *was* patterned after the
  32. other ANSI string functions.
  33.  
  34. Basically, ANSI states that "If an array is accessed beyond the end of
  35. an object, the behavior is undefined."  (Section 4.11.1, first para.)
  36.  
  37. A NULL character array has no size, so trying to access a member of it
  38. at *all* is accessing "beyond the end" of it.
  39.  
  40. I can put this in as an enhancement request for strstr(), but it can be
  41. argued that the current behavior is correct, at least according to ANSI
  42. specifications.  Just check for NULL yourself before calling it.
  43.  
  44. >[Example deleted]
  45. >
  46. >(Has been reported to EMITS)
  47.  
  48. Thanks.
  49. -- 
  50. ---------------
  51. Jim Cooper
  52. (jamie@unx.sas.com)                             bix: jcooper
  53.  
  54. Any opinions expressed herein are mine (Mine, all mine!  Ha, ha, ha!),
  55. and not necessarily those of my employer.
  56.