[Development] QJsonPrivate::Parser::parseObject broken on big endian

Olivier Goffart olivier at woboq.com
Mon Sep 3 13:21:54 CEST 2012


On Sunday 02 September 2012 23:10:18 Konstantin Tokarev wrote:
> Hi all,
> 
> When building Qt 5 on big endian host (PPC) I've found moc breaking on Qt
> classes containing Q_PLUGIN_METADATA with
> 
> ASSERT: "idx >= 0 && idx < s" in file
> ../../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 111
> 
> It turned out to be a fault of QJsonPrivate::Parser::parseObject which has
> different code for handling of big endian and little endian cases:
> 
>     if (parsedObject.offsets.size()) {
>         int tableSize = parsedObject.offsets.size()*sizeof(uint);
                                                     ^^^^^^^^^^^^^

The error is there:  one should multiply tableSize by sizeof(uint) only if one 
do a memcpy.
                                                    

>         table = reserveSpace(tableSize);
> #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
>         memcpy(data + table, parsedObject.offsets.constData(), tableSize);
> #else
>         offset *o = (offset *)(data + table);
>         for (int i = 0; i < tableSize; ++i)
>             o[i] = parsedObject.offsets[i];
> 
> #endif
>     }
> 
> Could anyone explain why memcpy cannot be used for big endian case here?

I guess that's because the offsets needs to be stored in little endian.
offset is a typedef to a class that has an assignement operator which swap the 
bytes.

-- 
Olivier

Woboq - Qt services and support - http://woboq.com



More information about the Development mailing list