xmlreader segfault on linux gcc-3.3.3 + fix

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
G.o.D
Posts: 4
Joined: Sat Mar 13, 2004 8:02 am
Location: Germany
Contact:

xmlreader segfault on linux gcc-3.3.3 + fix

Post by G.o.D »

the xml reader seqfaults on linux with gcc-3.3.3 and maybe others

i am not sure why, maybe wchar_t isnt 16 bit anymore, but the
header of the textfile doesnt show up as 0xfffe or 0xfeff but as 0x3cfffe

you can fix it, changin line #80 (void CTextReader::convertToUTF16())
of CTextReader.cpp from
(header[0] == 0xFFFE || header[0] == 0xFEFF))
to
((header[0]&0xffff) == 0xFFFE || (header[0]&0xffff) == 0xFEFF))

btw:

thanx for irrlicht. this is the easiest api for a 3d engine ever seen, and
i have seen a lot, including commercial.

i am looking forward to see a big endian able version... i could offer my
help in porting if needed (also i have a veeery slow ppc machine, which
is not really fun to code c++ with :) )
Tels
Posts: 65
Joined: Fri Feb 27, 2004 7:56 pm
Location: Antarctica
Contact:

Re: xmlreader segfault on linux gcc-3.3.3 + fix

Post by Tels »

G.o.D wrote:the xml reader seqfaults on linux with gcc-3.3.3 and maybe others

i am not sure why, maybe wchar_t isnt 16 bit anymore,
AFAIK it is 32 bit under most Unixes.
but the header of the textfile doesnt show up as 0xfffe or 0xfeff but as 0x3cfffe

you can fix it, changin line #80 (void CTextReader::convertToUTF16())
of CTextReader.cpp from
(header[0] == 0xFFFE || header[0] == 0xFEFF))
to
((header[0]&0xffff) == 0xFFFE || (header[0]&0xffff) == 0xFEFF))
Thanx for the fix!
i am looking forward to see a big endian able version... i could offer my
help in porting if needed (also i have a veeery slow ppc machine, which
is not really fun to code c++ with :) )
There were already some people working on this, please search the forums. (I forgot where, when or who :)

Tels
Perl + Irrlicht + Audiere = Game: http://bloodgate.com/perl/game
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Ah, did not think that this could be the problem. Thanks for posting this :)
G.o.D
Posts: 4
Joined: Sat Mar 13, 2004 8:02 am
Location: Germany
Contact:

update: fix was not complete

Post by G.o.D »

sorry, i didnt notice that this was only preventing the segfault, but the data of the xml file was completely ignored... so here is a fix, applyable with patch which finally makes the xml file reader reading the data (which i thought might be a good idea :) )

Code: Select all

--- orig.source/CTextReader.cpp 2004-03-04 16:25:36.000000000 +0100
+++ source/CTextReader.cpp      2004-03-14 09:52:53.000000000 +0100
@@ -77,14 +77,20 @@
        wchar_t* header = (wchar_t*)CData;
 
        if (CDataSize>=2 && 
-               (header[0] == 0xFFFE || header[0] == 0xFEFF))
+               ((header[0]&0xffff) == 0xFFFE || (header[0]&0xffff) == 0xFEFF))
        {
                // We've got UTF-16
 
-               TextData = &header[1];
+               TextData=new wchar_t[CDataSize];
+               for (u32 i=2; i<CDataSize; ++i) {
+                       TextData[i]=(wchar_t)(CData[i*2+1]<<8)|CData[i*2];
+               }
+               delete [] CData; 
+               CData = (c8*)TextData;
+
                TextDataSize = (CDataSize - 1) / (sizeof(wchar_t) / sizeof(c8)); // header 
 
-               if (header[0] == 0xFFFE)
+               if ((header[0]&0xffff) == 0xFFFE)
                {
                        // This is Big Endian, 
                        // convert to little endian.
G.o.D
Posts: 4
Joined: Sat Mar 13, 2004 8:02 am
Location: Germany
Contact:

Post by G.o.D »

yeah, i did it once again... the patch does not work correctly :)
so i now uploaded a final version which now works and is even tested this time...
here it is:

patch

you can call me microsoft :)
Post Reply