Moc: assert size of registered strings list is within INT_MAX range
Assert generator.strings.size() < INT_MAX after all strings have been registered. Parts of the public API, e.g. QMetaMethod::methodIndex and similar functions return int, and other parts of the code expect int values, at least for Qt6 this can't be changed, so use qsizetype internally and assert the values fit in an int. Change-Id: Ib226e9c19a578bbeaeb9bb767d756a9569fe57b3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
9cb08c4c0d
commit
845b5d63bf
|
|
@ -122,7 +122,7 @@ void Generator::strreg(const QByteArray &s)
|
|||
|
||||
int Generator::stridx(const QByteArray &s)
|
||||
{
|
||||
int i = strings.indexOf(s);
|
||||
int i = int(strings.indexOf(s));
|
||||
Q_ASSERT_X(i != -1, Q_FUNC_INFO, "We forgot to register some strings");
|
||||
return i;
|
||||
}
|
||||
|
|
@ -841,7 +841,7 @@ void Generator::generateProperties()
|
|||
int notifyId = p.notifyId;
|
||||
if (p.notifyId < -1) {
|
||||
// signal is in parent class
|
||||
const int indexInStrings = strings.indexOf(p.notify);
|
||||
const int indexInStrings = int(strings.indexOf(p.notify));
|
||||
notifyId = indexInStrings | IsUnresolvedSignal;
|
||||
}
|
||||
fprintf(out, ", 0x%.8x, uint(%d), %d,\n", flags, notifyId, p.revision);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ public:
|
|||
const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = nullptr,
|
||||
bool requireCompleteTypes = false);
|
||||
void generateCode();
|
||||
qsizetype registeredStringsCount() { return strings.size(); };
|
||||
|
||||
private:
|
||||
bool registerableMetaType(const QByteArray &propertyType);
|
||||
void registerClassInfoStrings();
|
||||
|
|
|
|||
|
|
@ -1138,6 +1138,12 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
|
|||
for (int i = 0; i < classList.size(); ++i) {
|
||||
Generator generator(&classList[i], metaTypes, knownQObjectClasses, knownGadgets, out, requireCompleteTypes);
|
||||
generator.generateCode();
|
||||
|
||||
// generator.generateCode() should have already registered all strings
|
||||
if (Q_UNLIKELY(generator.registeredStringsCount() >= std::numeric_limits<int>::max())) {
|
||||
error("internal limit exceeded: number of parsed strings is too big.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
fputs("", out);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue