Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrXML
some bugs and correction

Menuki
Guest
Quote
2013-10-22 12:32:36

Hello,

Being a long time user of irrXML, I post some correction I made.
Here the source code of each method I corrected.
All are in CXMLReaderImpl.h

Line 74 : I made parseCurrentNode() returning a boolean to correctly handle the end of file. So now read() look like:
	virtual bool read()
{
// if not end reached, parse the node
if (P && (unsigned int)(P - TextBegin) < TextSize - 1 && *P != 0)
{
return parseCurrentNode();
}

_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}

Line 93 : It is not a big problem but this line cause a unsigned to signed conversion warning with VS2010 so:
	virtual int getAttributeCount() const
{
return (int)Attributes.size();
}

Line 213 : parseCurrentNode() now returns a boolean. It returns false when it reach the end of file.
	bool parseCurrentNode()
{
char_type* start = P;

// more forward until '<' found
while(*P != L'<' && *P)
++P;

if (!*P)
return false;

if (P - start > 0)
{
// we found some text, store it
if (setText(start, P))
return true;
}

++P;

// based on current token, parse and report next element
switch(*P)
{
case L'/':
parseClosingXMLElement();
break;
case L'?':
ignoreDefinition();
break;
case L'!':
if (!parseCDATA())
parseComment();
break;
default:
parseOpeningXMLElement();
break;
}
return true;
}

Line 424: In bad formated file, if closing bracket is missing, parseClosingXMLElement() crashed because there is no "end of file" check in this line. So the while condition :
while(*P != L'>')
become
while(P && (unsigned int)(P - TextBegin) < TextSize - 1 && *P != 0 && *P != L'>')

Line 542: Replacing special characters do not always copy all trailing characters because of the '<' comperand which must be a '<=' comperand. The comparaison becomes :
if (oldPos <= origstr.size()-1)

Line 614: UTF8 file are not detected with VS2010. data8[] element are signed extented to int (0xEF becomes 0xFFFFFFEF) while UTF8[] element are non signed extended to int (0xEF becomes 0xEF). So the condition is never true. We have to tell the compiler to do a non signed extension of data8[] elements.
if (size >= 3 && data8[0] == UTF8[0] && data8[1] == UTF8[1] && data8[2] == UTF8[2])
become
if (size >= 3 &&
reinterpret_cast<unsigned char *>(data8)[0] == UTF8[0] &&
reinterpret_cast<unsigned char *>(data8)[1] == UTF8[1] &&
reinterpret_cast<unsigned char *>(data8)[2] == UTF8[2])



Menuki
Guest
Quote
2013-10-22 12:38:22

Finally I implemented a true UTF8 to UNICODE conversion in convertTextData().

Line 659, the code
			TextData = new char_type[sizeWithoutHeader];

for (int i=0; i<sizeWithoutHeader; ++i)
TextData[i] = (char_type)source[i];

TextBegin = TextData;
TextSize = sizeWithoutHeader;

// delete original data because no longer needed
delete [] pointerToStore;
become
define         MASKBITS                0x3F
define MASKBYTE 0x80
define MASK2BYTES 0xC0
define MASK3BYTES 0xE0
define MASK4BYTES 0xF0
define MASK5BYTES 0xF8
define MASK6BYTES 0xFC

TextData = new char_type[sizeWithoutHeader];
int i,n;
for (i=n=0; i<sizeWithoutHeader;)
{
char_type ch;

// 1110xxxx 10xxxxxx 10xxxxxx
if ((source[i] & MASK3BYTES) == MASK3BYTES)
{
ch = ((source[i] & 0x0F) << 12) | (
(source[i+1] & MASKBITS) << 6)
| (source[i+2] & MASKBITS);
i += 3;
}
// 110xxxxx 10xxxxxx
else if ((source[i] & MASK2BYTES) == MASK2BYTES)
{
ch = ((source[i] & 0x1F) << 6) | (source[i+1] & MASKBITS);
i += 2;
}
// 0xxxxxxx
else if (source[i] < MASKBYTE)
{
ch = (char_type)source[i];
i += 1;
}
else
{
++i;
continue;
}
TextData[n++] = ch;
}

TextBegin = TextData;
TextSize = n;

// delete original data because no longer needed
delete [] pointerToStore;


I hope this can help irrXML users to get the best of this good tool.


niko
Moderator
Quote
2013-10-23 05:58:23

Thanks :)


kyiv
Registered User
Quote
2014-05-24 19:16:39

At first glance the Menuki's fix looks correct and promising.
It was done more than a half year ago.
But I didn't see these changes in the available currently irrXML archive with sources.
Does anybody have explanation why?
Has irrXML available source repository and bug tracker?
I can't find them in SF, but only IrrlichtEngine :(


niko
Moderator
Quote
2014-05-25 20:56:12

Yes, irrXML isn't actively developed anymore, sorry.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact