Debug Assertion failed while displaying wxString Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Debug Assertion failed while displaying wxString

Post by Sunsawe » Fri May 25, 2007 6:33 am

Hi,

I'm usign this piece of code to read in a wxSocket (client):

Code: Select all

	wxChar buf2[1024] = {0};
	sock->Read(buf2,(sizeof(buf2)-1));
	while(sock->LastCount() > 0 && sock->IsConnected())
	{
		returnString.Append(wxString(wxConvUTF8.cMB2WC((char*)(buf2)), *wxConvCurrent));
		sock->Read(buf2,(sizeof(buf2)-1));
	}
	wxLogDebug(returnString);
It's working usually without any problem.
But since i'm trying to read an email received (from a mail server), which is pretty long, a Debug Assertion exception occurs. It occurs at the wxLogDebug line.

It comes from the "output.c" file (coming with visual studio), line 1120. The expression is:
(state != ST_INVALID)

Can someone explain why? and how to solve it?

Thanks

Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Post by Sunsawe » Mon May 28, 2007 5:45 pm

well... I'm still trying to solve that.
I noticed that before the mail, all the messages from the server were shorter than the buffer size.

I thought that the problem could come from the loop ( that appends the buffer content to a string).
To test that, i reduce the buffer size to 8 but... it did the same thing.
I mean that for all the messages before the mail, it works (evenif it was looping and appending the buffer content to the string) and the mail failed.

Is there any restriction on a wxString size? Are 22000 characters too many?
What can cause this state to be invalid?

Thanks

Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Post by Sunsawe » Tue May 29, 2007 7:06 am

i performed some more tests.
I tried to display every pieces of message that were received.
The exception has been fired before.

So for each full buffer after i appended the content to the string, i displayed it with :

Code: Select all

wxLogDebug(wxString(wxConvUTF8.cMB2WC((char*)(buf2)), *wxConvCurrent));
The last part of the string was:

Code: Select all

positives=A0:  99,3=A0%
Me
And the buffer content was just the 7 last characters (\n\r not visible of course)

Code: Select all

A0%
Me
And that is what has fired the exception.

Can someone explain what's wrong with that?

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Tue May 29, 2007 7:25 am

Hi,

really wxLogDebug is:
void wxLogDebug(const char *formatString, ...)

From MSDN:

Format specifications always begin with a percent sign (%) and are read left to right. When printf encounters the first format specification (if any), it converts the value of the first argument after format and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Post by Sunsawe » Tue May 29, 2007 9:23 am

Ok.... I can't test it now but it sounds interesting.
Is there any other "dangerous" characters?
Is there a way to "secure" them or can i just replace all % in the string by \% ?

Thanks

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Tue May 29, 2007 9:37 am

Sunsawe wrote:Is there any other "dangerous" characters?
For this case i don't think so.
Is there a way to "secure" them or can i just replace all % in the string by \% ?
Thanks
% -> %%
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Post Reply