QMetaObjectBuilder: Avoid arithmetic on null pointer

In Prepare mode, "buf" is a null pointer. We never dereference it, but we
still compute an offset from it to obtain a pointer to a (then unused)
QMetaObjectPrivater.
clang's UBSan complains about this, so initialize the pointer to nullptr
instead when in Prepare mode.

Pick-to: 6.6 6.5
Change-Id: Id9d78058f72bb1b44440d07f565374f3eb3c20fd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit d3d224f546d933acef53f7592fea7d69072f7d55)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2024-01-19 11:46:07 +01:00 committed by Qt Cherry-pick Bot
parent a338e222cc
commit f1bd8bcaba

View File

@ -1162,8 +1162,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
}
// Populate the QMetaObjectPrivate structure.
QMetaObjectPrivate *pmeta
= reinterpret_cast<QMetaObjectPrivate *>(buf + size);
QMetaObjectPrivate *pmeta = buf ? reinterpret_cast<QMetaObjectPrivate *>(buf + size)
: nullptr;
//int pmetaSize = size;
dataIndex = MetaObjectPrivateFieldCount;
int methodParametersDataSize =