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

lars.knoll at nokia.com lars.knoll at nokia.com
Mon Sep 3 10:12:38 CEST 2012


Hi,

On Sep 2, 2012, at 9:10 PM, ext Konstantin Tokarev <annulen at yandex.ru> 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);
>        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?

The big endian code has not been tested at all so far, because I simply didn't have a big endian machine available. So there could be bugs (or stupid things) in the code paths for big endian. I'd appreciate any patches to fix it. For testing, the auto test in tests/auto/corelib/json is pretty complete, so once that passes you should be in good shape.

Cheers,
Lars




More information about the Development mailing list