Article View: comp.sys.next.programmer
Article #1965Re: NXWriteTypes() of 'char *'
From: Gregory H. Anderson
Date: Thu, 24 Dec 1992 20:19
Date: Thu, 24 Dec 1992 20:19
36 lines
2033 bytes
2033 bytes
In article <1992Dec23.131946.14537@rdg.dec.com> jacksonc@uproar.enet.dec.com (Chris Jackson @ IME) writes: > > My experience seems to suggest that using NXWriteTypes() to archive a > 'char *' only works if the 'char *' is not NULL. If it *is* NULL, then > a memory violation results in 'strlen()' in NeXT code when the object > concerned is read from the archive. > > Can anyone out there confirm that this is the case and whether or not it > is the expected behaviour ? If it is the expected behaviour, I presume > I have to explicitly code around it ? Next question - is there a > recommended way of doing so ? Well, yes... but this is true for all of C, not just NeXT read/write calls. When an object is first instantiated, all ivars are set to 0/NULL. If you never assign anything to the pointer, it stays NULL, and reads/writes NULL. That is exactly as it should be. The problem is that strlen (and str[n]cpy and str[n]cmp), at least as implemented in the NeXT libraries, do not guard against NULL in source or dest. Frankly, I think the overhead would be worth it, but they chose not to. Write your own strxxx functions (they're not that complicated) and link them in to override the default library implementations, or give yours a unique name and use a #define strlen mystrlen to substitute yours for the library copy at compile time. -- Gregory H. Anderson | Thus spake the master programmer: Master Programmer / Manager | "Let the programmers be many and Anderson Financial Systems | the managers few; then all will be greg@afs.com (Nextmail OK) | productive." -- Tao of Programming
Technical Details
Message-ID:
<1992Dec24.201953.2341@afs.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!psinntp!afs!gregReferences:
<1992Dec23.131946.14537@rdg.dec.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!afs!greg From: greg@afs.com (Gregory H. Anderson) Subject: Re: NXWriteTypes() of 'char *' Message-ID: <1992Dec24.201953.2341@afs.com> Sender: greg@afs.com Reply-To: greg@afs.com References: <1992Dec23.131946.14537@rdg.dec.com> Date: Thu, 24 Dec 1992 20:19:53 GMT Lines: 36