[pim/libkleo] autotests: cppcheck: Silence bogus containerOutOfBounds error
Ingo Klöcker <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit c3b090f2055cd0c4fb1aa6f47a24bb7d8c4d3045 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 30/07/2026 at 12:08.
Pushed by kloecker into branch 'master'.
cppcheck: Silence bogus containerOutOfBounds error
cppcheck reports:
> Out of bounds access in
> 'allCharsExceptControlCharsAndSpaceAndPercentAndPlus.begin()+4',
> if 'allCharsExceptControlCharsAndSpaceAndPercentAndPlus' size is 2
> and 'allCharsExceptControlCharsAndSpaceAndPercentAndPlus.begin()+4'
> is at position 4 from the beginning
Apparently, cppcheck "thinks" that the QByteArray might have size 2
because two arguments are passed to the c'tor as brace-enclosed
initializer list. Use parentheses instead of braces to make cppcheck
happy.
M +1 -1 autotests/assuantest.cpp
https://invent.kde.org/pim/libkleo/-/commit/c3b090f2055cd0c4fb1aa6f47a24bb7d8c4d3045
diff --git a/autotests/assuantest.cpp b/autotests/assuantest.cpp
index c7c8ab4f..5e2d67c7 100644
--- a/autotests/assuantest.cpp
+++ b/autotests/assuantest.cpp
@@ -21,7 +21,7 @@ private Q_SLOTS:
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QByteArray>("expected");
- QByteArray allCharsExceptControlCharsAndSpaceAndPercentAndPlus{256 - 32 - 1 - 1 - 1, Qt::Uninitialized};
+ QByteArray allCharsExceptControlCharsAndSpaceAndPercentAndPlus(256 - 32 - 1 - 1 - 1, Qt::Uninitialized);
// initialize the first 4 characters with the characters from '!' to '$' (the one before '%'), i.e. 0x21...0x24
std::iota(allCharsExceptControlCharsAndSpaceAndPercentAndPlus.begin(), allCharsExceptControlCharsAndSpaceAndPercentAndPlus.begin() + 4, '!');
// initialize the next 5 characters with the characters from '&' (the one after '%') to '*' (the one before '+'), i.e. 0x26...0x2A