Bug in UStr find and Replace

Guy Rouillier <[email protected]> Fri, 10 Mar 2006 01:14:08 -0500
Newsgroups gmane.comp.version-control.cvs.gui.devel
Message-ID <[email protected]>
As I was putting finishing touches on some code changes for gCvs, I 
stumbled across a bug in rf/UStr.cpp.  In method

	int UStr::find(const char* thestr) const

the statement

	return buf - m_str;

evaluates to zero if thestr is at the beginning of the current string. 
But zero is defined by this function to mean "not found".

Changing the not-found value to -1 (minus one) fixes it for me, but I 
have no idea what this breaks in other parts of the code.  Of course, 
any code depending on this behavior is by definition broken itself.

Which brings me to the following method:

	const UStr & UStr::Replace(const char* which, char *bywhich)

which contains the following invocation of find() above:

	while((pos = find(which)) != 0)

To accommodate the above suggested change in find(), I changed this line to

	while((pos = find(which)) >= 0)

I have not committed this change to CVS yet, pending outcome of any 
ensuing discussion.  I'm working on a branch at the moment (GCVS_GTK2), 
so I can go ahead and commit if that would help.

-- 
Guy Rouillier


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cvsgui-dev/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/