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 » [FIXED] ToUpper, ToLower,and ToAscii (char*, int) causes AssertFailed
Re: [BUG] ToUpper, ToLower,and ToAscii (char*, int) causes AssertFailed [message #46595 is a reply to message #46591] Mon, 06 June 2016 12:56 Go to previous messageGo to previous message
omari is currently offline  omari
Messages: 276
Registered: March 2010
Experienced Member
Yes, there is tow,

a - the first can be avoided by specifying a charset,

a possible solution to this is to test if charset is equal to UTF8 (like others ToUpper functions), and do not call s_cset(charset) in this case.

replace : (in file CharSet.cpp, line ~ 2660)
void ToUpper(char *t, const char *s, int len, byte charset)
{
	charset = ResolveCharset(charset);
	CharSetData& cs = s_cset(charset);
	const char *lim = s + len;
	while(s < lim)
		*t++ = cs.FromUnicode(UPP::ToUpper(cs.ToUnicode(*s++)));
}


by:
void ToUpper(char *t, const char *s, int len, byte charset)
{
	charset = ResolveCharset(charset);
	if(charset == CHARSET_UTF8)
	{
		String u = ToUtf8(ToUpper(FromUtf8(s, len)));
		memcpy(t, ~u, len);
		return;
	}
	
	CharSetData& cs = s_cset(charset);
	const char *lim = s + len;
	while(s < lim)
		*t++ = cs.FromUnicode(UPP::ToUpper(cs.ToUnicode(*s++)));
}


b - here a test case for the second BUG:
the code below produce EXCEPTION_ACCESS_VIOLATION
CONSOLE_APP_MAIN
{
	char* s = "abcd";
	ToUpper(s, s, 4, CHARSET_WIN1250);
}

but the code below work as expected:
CONSOLE_APP_MAIN
{
	char* s = "abcd";
	StringBuffer r(4);
	ToUpper(r, s, 4, CHARSET_WIN1250);
}


then, the bug can be resolved by replacing : (in file CharSet.cpp, line ~ 2630)
void ToUpper(char *s, int len, byte charset)
{
	ToUpper(s, s, len, charset);
}


by
void ToUpper(char *s, int len, byte charset)
{
	StringBuffer r(len);
	ToUpper(r, s, len, charset);
	memcpy(s, r, len);
}



regards
omari.

[Updated on: Mon, 06 June 2016 13:21]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to handle a lack of memory
Next Topic: [FEATURE] Accessing to Alternate Win Registry View (patch included)
Goto Forum:
  


Current Time: Sun Aug 24 13:27:30 CEST 2025

Total time taken to generate the page: 0.05530 seconds