[sword-cvs] sword/src/utilfuns swbuf.cpp,1.18,1.19

Martin Gruner mg.pub at gmx.net
Thu Jun 10 12:12:09 MST 2004


We'd probably need to test and see how much difference it makes. Maybe I can 
come up with numbers later.
I'm not against removing the check, but I just did not know that the user has 
to care for that. Sword should be kindof robust. Just a few days ago I fixed 
a bug that made it crash on a malformed ModDrv= line. Things like that should 
not happen. SWBuf is different though, cause it is pretty much internal and 
will only be seen by developers.

mg

Am Donnerstag, 10. Juni 2004 11:49 schrieb Troy A. Griffitts:
> Hey Martin,
> 	Wish we could chat, but I don't have that port open at work (WORK!!! OH
> NO!)
>
> 	:)
>
> 	I'm not sure if this is correct.
>
> 	Modus operandi for the standard libs is usually to force this check out
> of the library, cf. strlen, strcat, et. al.  It's a speed hit at these
> lower levels that might have to be fast.  I like the check, but it might
> need to be removed when optimizing, and we can safely refer to the other
> standard c-string calls and point out their operation when passed a 0
> (not a "\0", by the way-- our code and theirs works fine when passed a
> "\0")
>
> 	Thoughts?
>
> 		-Troy.
>
> sword at www.crosswire.org wrote:
> > Committed by: mgruner
> >
> > Update of /cvs/core/sword/src/utilfuns
> > In directory www:/tmp/cvs-serv17313/src/utilfuns
> >
> > Modified Files:
> > 	swbuf.cpp
> > Log Message:
> > mgruner: bugfix. swbuf crashed when trying to append "\0".
> > 	C is evil. We need to be more careful with pointer stuff!
> >
> >
> > Index: swbuf.cpp
> > ===================================================================
> > RCS file: /cvs/core/sword/src/utilfuns/swbuf.cpp,v
> > retrieving revision 1.18
> > retrieving revision 1.19
> > diff -u -d -r1.18 -r1.19
> > --- swbuf.cpp	15 Apr 2004 14:39:12 -0000	1.18
> > +++ swbuf.cpp	10 Jun 2004 16:02:14 -0000	1.19
> > @@ -140,6 +140,8 @@
> >  * SWBuf::append - appends a value to the current value of this SWBuf
> >  */
> >  void SWBuf::append(const char *str, const long max) {
> > +	if (!str) //A null string was passed
> > +		return;
> >  	//make sure we only copy strlen(str) bytes if max is larger than
> > strlen(str) is unsigned long str_len = strlen( str );
> >  	unsigned long len = (max > -1) ? ((max <= str_len) ? max : str_len) :
> > str_len; @@ -178,6 +180,9 @@
> >  }
> >
> >  void SWBuf::insert(const unsigned long pos, const char* str, const
> > signed long max) { +	if (!str) //A null string was passed
> > +		return;
> > +
> >  	const int len = (max > -1) ? max : strlen(str);
> >
> >  	if (!len || (pos > length())) //nothing to do, return
> >
> > _______________________________________________
> > sword-cvs mailing list
> > sword-cvs at crosswire.org
> > http://www.crosswire.org/mailman/listinfo/sword-cvs
>
> _______________________________________________
> sword-cvs mailing list
> sword-cvs at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-cvs


More information about the sword-cvs mailing list