diff options
author | Dominik Holland <dominik.holland@qt.io> | 2022-07-27 20:32:31 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-28 16:32:17 +0000 |
commit | 79da0edb97454afc04e79c4c0f221958f8c1e736 (patch) | |
tree | c41501d0ba36be169a84055ed24d6eebd5f753a9 | |
parent | 16d83dea6f09262adea1ec14aa48a4cac70c609f (diff) |
repc: Fix warning in generated code
Check the array bounds using sizeof before access to make the compiler
happy.
Otherwise the following warning is generated:
warning: array subscript 1 is above array bounds of ‘const int [1]’ [-Warray-bounds]
Fixes: QTBUG-97790
Change-Id: I52b36b065b9f62188e5bfc157081650ca3ee159e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
(cherry picked from commit acd888220b9d600fe057249d43bd3934ae0cbad5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tools/repc/repcodegenerator.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp index 553d152..dcf3730 100644 --- a/tools/repc/repcodegenerator.cpp +++ b/tools/repc/repcodegenerator.cpp @@ -1218,20 +1218,26 @@ void RepCodeGenerator::generateSourceAPI(const ASTClass &astClass) << Qt::endl; m_stream << QStringLiteral(" int sourceEnumIndex(int index) const override") << Qt::endl; m_stream << QStringLiteral(" {") << Qt::endl; - m_stream << QStringLiteral(" if (index < 0 || index >= m_enums[0])") << Qt::endl; + m_stream << QStringLiteral(" if (index < 0 || index >= m_enums[0]" + " || index + 1 >= int(std::size(m_enums)))") + << Qt::endl; m_stream << QStringLiteral(" return -1;") << Qt::endl; m_stream << QStringLiteral(" return m_enums[index+1];") << Qt::endl; m_stream << QStringLiteral(" }") << Qt::endl; m_stream << QStringLiteral(" int sourcePropertyIndex(int index) const override") << Qt::endl; m_stream << QStringLiteral(" {") << Qt::endl; - m_stream << QStringLiteral(" if (index < 0 || index >= m_properties[0])") << Qt::endl; + m_stream << QStringLiteral(" if (index < 0 || index >= m_properties[0]" + " || index + 1 >= int(std::size(m_properties)))") + << Qt::endl; m_stream << QStringLiteral(" return -1;") << Qt::endl; m_stream << QStringLiteral(" return m_properties[index+1];") << Qt::endl; m_stream << QStringLiteral(" }") << Qt::endl; m_stream << QStringLiteral(" int sourceSignalIndex(int index) const override") << Qt::endl; m_stream << QStringLiteral(" {") << Qt::endl; - m_stream << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << Qt::endl; + m_stream << QStringLiteral(" if (index < 0 || index >= m_signals[0]" + " || index + 1 >= int(std::size(m_signals)))") + << Qt::endl; m_stream << QStringLiteral(" return -1;") << Qt::endl; m_stream << QStringLiteral(" return m_signals[index+1];") << Qt::endl; m_stream << QStringLiteral(" }") << Qt::endl; |