🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
2 messages
2 total messages Started by Chris Jackson IME Wed, 23 Dec 1992 13:19
NXWriteTypes() of 'char *'
#1951
Author: Chris Jackson IME
Date: Wed, 23 Dec 1992 13:19
15 lines
1061 bytes
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 ?

Thanks, in anticipation,

Chris.
Re: NXWriteTypes() of 'char *'
#1965
Author: Gregory H. Anderson
Date: Thu, 24 Dec 1992 20:19
36 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads