home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / os2 / programm / 3718 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.4 KB  |  34 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!pacbell.com!decwrl!ampex!cjensen
  3. From: cjensen@ampex.com (Colin Jensen)
  4. Subject: Re: EMX library bug.
  5. Message-ID: <1992Jul22.185306.10692@ampex.com>
  6. Sender: usenet@ampex.com (News Poster)
  7. Nntp-Posting-Host: mer-s4-14
  8. Organization: Ampex Corporation, Redwood City CA
  9. References: <ReiBoB5w164w@dvss.UUCP>
  10. Date: Wed, 22 Jul 1992 18:53:06 GMT
  11. Lines: 21
  12.  
  13. In article <ReiBoB5w164w@dvss.UUCP> dvss!jtroy@udel.edu (Jay Troy) writes:
  14. >I think I've discovered an EMX library bug.  The standard library function
  15. >strtok causes an access violation in every combination that I've tried.  The
  16. >following simple C program illustrates this problem:
  17.  
  18. >    char *ch = "3.4 4.1";
  19. >    strcpy(temp, strtok(ch," "));
  20.  
  21. I don't know anything about EMX, but your code is certainly problematic.
  22. A C compiler is free to store strings constants like "3.4 4.1" in 
  23. read-only memory [hence their name].  Since strtok will try to write 
  24. into that memory, an access violation should be expected.
  25.  
  26. To be portable, you need to copy that string either into an automatic variable
  27. or copy it into some malloc'ed memory.
  28.  
  29. Under UNIX, you can pass gcc the option -fwritable-strings to tell gcc you
  30. really want to be able to write into string constants.  Perhaps this would
  31. solve your problem with EMX.
  32. -- 
  33. Colin Jensen (cjensen@ampex.com)
  34.