Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Bug: AString<B>::ReverseFind broken for wchar
Bug: AString<B>::ReverseFind broken for wchar [message #42257] Sun, 02 March 2014 17:49 Go to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Small bug in SVN rev6982:

in function
int AString<B>::ReverseFind(int len, const tchar *s, int from) const


change line
if(*s == *p && memcmp(s, p, len) == 0)

to
if(*s == *p && memcmp(s, p, len*sizeof(tchar)) == 0)


Thanks,
Hans
Re: Bug: AString<B>::ReverseFind broken for wchar [message #42258 is a reply to message #42257] Sun, 02 March 2014 18:15 Go to previous messageGo to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Similar bug is in new code of string::Find():

Please change in
template <class tchar>
force_inline bool svo_memeq(const tchar *a, const tchar *b, int len)


the second line
		return memcmp(a, b, len) == 0;

to
		return memcmp(a, b, len*sizeof(tchar)) == 0;


Thanks,
Hans
Re: Bug: AString<B>::ReverseFind broken for wchar [message #42259 is a reply to message #42257] Sun, 02 March 2014 18:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I might be wrong, but:

int AString<B>::ReverseFind(int len, const tchar *s, int from) const
{
	ASSERT(from >= 0 && from <= GetLength());
	if(from < GetLength()) {
		const tchar *ptr = B::Begin();
		const tchar *p = ptr + from - len + 1;
		len *= sizeof(tchar); <<<<<<<<<<<<<<<<<<<<<<<<<<
		while(p >= ptr) {
			if(*s == *p && memcmp(s, p, len) == 0)
				return (int)(p - ptr);
			p--;
		}
	}
	return -1;
}


should do the trick, IMO?

But tvo_memeq problem is real, thank you! (fixed)

Mirek
Re: Bug: AString<B>::ReverseFind broken for wchar [message #42260 is a reply to message #42259] Sun, 02 March 2014 18:56 Go to previous message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Mirek you are right Wink

I'v overlooked this.
ReverseFind is not buggy.

Hans
Previous Topic: To get xml errors from LoadFromXML
Next Topic: String should implement the Boyer Moore algo
Goto Forum:
  


Current Time: Fri Mar 29 11:44:55 CET 2024

Total time taken to generate the page: 0.01888 seconds