From 3a53fd9f23ab19ad83093750778f85ab318b9b7a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 2 Sep 2020 10:40:59 +0200 Subject: Make moc ready for when null byte-arrays have null constData() Various places in moc relied on the magic behavior of QByteArray, that provided a non-null pointer to a null byte when the byte array was null, resulting in crashes when QT5_NULL_STRINGS is turned off. Fixed them to cope with this (and optimised out some pointless effort, when empty QByteArrays are involved, in the process). Change-Id: I617a878eb2e9ac8be244080efa1f0de4ac9a68a2 Reviewed-by: Fabian Kosmale --- src/tools/moc/generator.cpp | 14 +++++++++----- src/tools/moc/moc.cpp | 7 +++---- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 1fe366dde4..4ee68102b9 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2013 Olivier Goffart +** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2019 Olivier Goffart ** Copyright (C) 2018 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -283,7 +283,7 @@ void Generator::generateCode() if (i != strings.size() - 1) fputc(',', out); const QByteArray comment = str.length() > 32 ? str.left(29) + "..." : str; - fprintf(out, " // \"%s\"\n", comment.constData()); + fprintf(out, " // \"%s\"\n", comment.size() ? comment.constData() : ""); idx += str.length() + 1; for (int j = 0; j < str.length(); ++j) { if (str.at(j) == '\\') { @@ -1466,8 +1466,12 @@ void Generator::generateSignal(FunctionDef *def,int index) for (int j = 0; j < def->arguments.count(); ++j) { const ArgumentDef &a = def->arguments.at(j); if (j) - fprintf(out, ", "); - fprintf(out, "%s _t%d%s", a.type.name.constData(), offset++, a.rightType.constData()); + fputs(", ", out); + if (a.type.name.size()) + fputs(a.type.name.constData(), out); + fprintf(out, " _t%d", offset++); + if (a.rightType.size()) + fputs(a.rightType.constData(), out); } if (def->isPrivateSignal) { if (!def->arguments.isEmpty()) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 228a21e3c2..15c35234c9 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Olivier Goffart +** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2019 Olivier Goffart ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the tools applications of the Qt Toolkit. @@ -46,8 +46,7 @@ QT_BEGIN_NAMESPACE // only moc needs this function static QByteArray normalizeType(const QByteArray &ba) { - QByteArray result = normalizeTypeInternal(ba.constBegin(), ba.constEnd()); - return result; + return ba.size() ? normalizeTypeInternal(ba.constBegin(), ba.constEnd()) : ba; } bool Moc::parseClassHead(ClassDef *def) -- cgit v1.2.3