home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / next / programm / 7911 < prev    next >
Encoding:
Text File  |  1992-12-24  |  1.9 KB  |  48 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!psinntp!afs!greg
  3. From: greg@afs.com (Gregory H. Anderson)
  4. Subject: Re: NXWriteTypes() of 'char *'
  5. Message-ID: <1992Dec24.201953.2341@afs.com>
  6. Sender: greg@afs.com
  7. Reply-To: greg@afs.com
  8. References: <1992Dec23.131946.14537@rdg.dec.com>
  9. Date: Thu, 24 Dec 1992 20:19:53 GMT
  10. Lines: 36
  11.  
  12. In article <1992Dec23.131946.14537@rdg.dec.com>  
  13. jacksonc@uproar.enet.dec.com (Chris Jackson @ IME) writes:
  14. > My experience seems to suggest that using NXWriteTypes() to archive a 
  15. > 'char *' only works if the 'char *' is not NULL.  If it *is* NULL, then 
  16. > a memory violation results in 'strlen()' in NeXT code when the object 
  17. > concerned is read from the archive.
  18. > Can anyone out there confirm that this is the case and whether or not it 
  19. > is the expected behaviour ?  If it is the expected behaviour, I presume 
  20. > I have to explicitly code around it ?  Next question - is there a 
  21. > recommended way of doing so ?
  22.  
  23. Well, yes... but this is true for all of C, not just NeXT read/write  
  24. calls.
  25.  
  26. When an object is first instantiated, all ivars are set to 0/NULL. If you  
  27. never assign anything to the pointer, it stays NULL, and reads/writes  
  28. NULL. That is exactly as it should be. The problem is that strlen (and  
  29. str[n]cpy and str[n]cmp), at least as implemented in the NeXT libraries,  
  30. do not guard against NULL in source or dest. Frankly, I think the overhead  
  31. would be worth it, but they chose not to.
  32.  
  33. Write your own strxxx functions (they're not that complicated) and link  
  34. them in to override the default library implementations, or give yours a  
  35. unique name and use a 
  36.  
  37. #define strlen mystrlen
  38.  
  39. to substitute yours for the library copy at compile time.
  40.  
  41. --
  42. Gregory H. Anderson          | Thus spake the master programmer: 
  43. Master Programmer / Manager  | "Let the programmers be many and  
  44. Anderson Financial Systems   | the managers few; then all will be 
  45. greg@afs.com  (Nextmail OK)  | productive." -- Tao of Programming
  46.