Cross-platform SDK and HTML5 tools for mobile app development
X
 
2 posts / 0 new
Last post
glemi
glemi's picture
Offline
Joined: 22 Jun 2012
Posts:
panic when parsing xml

I'm new to mosync and app development. I would like to use the xml parser to extract some information (a list of users) from a web page that I download using a http connection. When I try to parse the data the app crashes (in an android 2.0 emulator) with panic code 40035.

Here is my parser:

class UserListParser :
	private Mtx::XmlListener,
	private Mtx::MtxListener
{
public:
	void parse(MAUtil::String& tagdata);

private:

	// for test purposes (I derive a screen from UserListParser that implements
	// someEvent() and have it display a debug message)
	virtual void someEvent(MAUtil::String stuff) = 0;

	// from XmlListener
	void mtxEncoding(const char* value);
	void mtxTagStart(const char* name, int len);
	void mtxTagAttr(const char* attrName, const char* attrValue);
	void mtxTagStartEnd();
	void mtxTagData(const char* data, int len);
	void mtxTagEnd(const char* name, int len);
	void mtxParseError(int offset);
	void mtxEmptyTagEnd();
	unsigned char mtxUnicodeCharacter(int unicode);

	// from MtxListener
	void mtxDataRemains(const char* data, int len);

	// private members
	MAUtil::String tagdata;
	Mtx::Context parser;
};

here is the implementation of the only public method:

void UserListParser::parse(MAUtil::String& tagdata)
{
	// copy the data
	UserListParser::tagdata = tagdata;

	// start parsing, here is where it crashes
	parser.feed(tagdata.pointer());

	// the following line is not executed
	someEvent("not crashed... yet");
}

here is what happens in the screen (which is derived from UserListParser):

void TextScreen::someEvent(MAUtil::String stuff)
{
	addText(stuff);
}

void TextScreen::addText(const MAUtil::String& str)
{
	 MAUtil::String text = mainLabel->getText();
	 text.append("\n", 1);
	 text.append(str.c_str(), str.length());
	 mainLabel->setText(text);
}

I imagine it is maybe a problem with the string handling.

Is the char* data returned by String::pointer() zero-terminated? What is the difference between pointer() and c_str()?

What could I possibly be doing wrong? Thanks for any help with this.

I hope I'm in the right section of the forum with this question.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, tough problem. 40035 is an illegal instruction error - I'm 99.999% sure that this will come down to a memory problem - something isn't being allocated/deallocated properly.

What is this?

    // copy the data
    UserListParser::tagdata = tagdata

>>Is the char* data returned by String::pointer() zero-terminated?

Yes

>>What is the difference between pointer() and c_str()?

This code looks OK, I think you've got a problem somewhere else - an object not correctly deleted, or a buffer overflow.  I think that your code is overwriting itself, but the problem line isn't in the forum post.

pointer() is a char*, c_str() is const char*