summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-12-06 17:32:05 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-01-16 10:16:40 +0000
commitc563762bf4496e8bd415dd8accd06a3e1723b7ee (patch)
tree94bdb09b4f9eddb43108bf1b47fe886619e6b5ef
parent85a6acf73c4fd8c720cb920547422a30d42e2d5e (diff)
Avoid number conversion issues
Use unsigned types where we mean unsigned and signed types where we mean signed. Check the integer range before casting to a smaller type. Change-Id: Ia2150282e9763855c495bd5547e2bc176d8d93be Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
-rw-r--r--app/perftracingdata.h18
-rw-r--r--app/perfunwind.cpp5
-rw-r--r--app/perfunwind.h2
-rw-r--r--tests/auto/elfmap/tst_elfmap.cpp22
-rw-r--r--tests/auto/perfdata/tst_perfdata.cpp3
5 files changed, 27 insertions, 23 deletions
diff --git a/app/perftracingdata.h b/app/perftracingdata.h
index 4427f8d..3c83daf 100644
--- a/app/perftracingdata.h
+++ b/app/perftracingdata.h
@@ -24,16 +24,16 @@
#include <QHash>
#include <QVector>
-enum FormatFlags
+enum FormatFlags: quint32
{
- FIELD_IS_ARRAY = 1,
- FIELD_IS_POINTER = 2,
- FIELD_IS_SIGNED = 4,
- FIELD_IS_STRING = 8,
- FIELD_IS_DYNAMIC = 16,
- FIELD_IS_LONG = 32,
- FIELD_IS_FLAG = 64,
- FIELD_IS_SYMBOLIC = 128,
+ FIELD_IS_ARRAY = 1 << 0,
+ FIELD_IS_POINTER = 1 << 1,
+ FIELD_IS_SIGNED = 1 << 2,
+ FIELD_IS_STRING = 1 << 3,
+ FIELD_IS_DYNAMIC = 1 << 4,
+ FIELD_IS_LONG = 1 << 5,
+ FIELD_IS_FLAG = 1 << 6,
+ FIELD_IS_SYMBOLIC = 1 << 7,
};
struct FormatField
diff --git a/app/perfunwind.cpp b/app/perfunwind.cpp
index 0830f92..849b220 100644
--- a/app/perfunwind.cpp
+++ b/app/perfunwind.cpp
@@ -565,7 +565,10 @@ void PerfUnwind::analyze(const PerfRecordSample &sample)
const auto &attribute = m_attributes.at(attributesId);
if (attribute.type() == PerfEventAttributes::TYPE_TRACEPOINT) {
type = TracePointSample;
- eventFormatId = attribute.config();
+ if (attribute.config() > std::numeric_limits<qint32>::max())
+ qWarning() << "Excessively large event format ID" << attribute.config();
+ else
+ eventFormatId = static_cast<qint32>(attribute.config());
}
}
diff --git a/app/perfunwind.h b/app/perfunwind.h
index 36b8f22..a18d6a0 100644
--- a/app/perfunwind.h
+++ b/app/perfunwind.h
@@ -92,7 +92,7 @@ public:
UnwindInfo() : frames(0), unwind(nullptr), sample(nullptr), maxFrames(64),
firstGuessedFrame(-1), isInterworking(false) {}
- QHash<quint32, QHash<quint64, Dwarf_Word>> stackValues;
+ QHash<qint32, QHash<quint64, Dwarf_Word>> stackValues;
QVector<qint32> frames;
PerfUnwind *unwind;
const PerfRecordSample *sample;
diff --git a/tests/auto/elfmap/tst_elfmap.cpp b/tests/auto/elfmap/tst_elfmap.cpp
index 58ce323..aac377b 100644
--- a/tests/auto/elfmap/tst_elfmap.cpp
+++ b/tests/auto/elfmap/tst_elfmap.cpp
@@ -169,7 +169,7 @@ private slots:
void benchRegisterElfDisjunct()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
const quint64 ADDR_STEP = 1024;
const quint64 MAX_ADDR = ADDR_STEP * numElfMaps;
const quint64 LEN = 1024;
@@ -183,16 +183,16 @@ private slots:
void benchRegisterElfDisjunct_data()
{
- QTest::addColumn<int>("numElfMaps");
- QTest::newRow("10") << 10;
- QTest::newRow("100") << 100;
- QTest::newRow("1000") << 1000;
- QTest::newRow("2000") << 2000;
+ QTest::addColumn<uint>("numElfMaps");
+ QTest::newRow("10") << 10u;
+ QTest::newRow("100") << 100u;
+ QTest::newRow("1000") << 1000u;
+ QTest::newRow("2000") << 2000u;
}
void benchRegisterElfOverlapping()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
const quint64 ADDR_STEP = 1024;
const quint64 MAX_ADDR = ADDR_STEP * numElfMaps;
quint64 len = MAX_ADDR;
@@ -212,7 +212,7 @@ private slots:
void benchRegisterElfExpanding()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
const quint64 ADDR = 0;
const quint64 LEN_STEP = 1024;
const quint64 MAX_LEN = LEN_STEP * numElfMaps;
@@ -231,7 +231,7 @@ private slots:
void benchFindElfDisjunct()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
PerfElfMap map;
@@ -258,7 +258,7 @@ private slots:
void benchFindElfOverlapping()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
PerfElfMap map;
@@ -285,7 +285,7 @@ private slots:
void benchFindElfExpanding()
{
- QFETCH(int, numElfMaps);
+ QFETCH(uint, numElfMaps);
PerfElfMap map;
diff --git a/tests/auto/perfdata/tst_perfdata.cpp b/tests/auto/perfdata/tst_perfdata.cpp
index e9fc85f..bf4b72c 100644
--- a/tests/auto/perfdata/tst_perfdata.cpp
+++ b/tests/auto/perfdata/tst_perfdata.cpp
@@ -164,8 +164,9 @@ void TestPerfData::testTracingData()
const PerfParserTestClient::AttributeEvent attribute
= client.attribute(sample.attributeId);
QCOMPARE(attribute.type, 2u);
+ QVERIFY(attribute.config <= std::numeric_limits<qint32>::max());
const PerfParserTestClient::TracePointFormatEvent format
- = client.tracePointFormat(attribute.config);
+ = client.tracePointFormat(static_cast<qint32>(attribute.config));
QCOMPARE(client.string(format.system), QByteArray("probe_untitled1"));
QCOMPARE(client.string(format.name), QByteArray("main"));
QCOMPARE(format.flags, 0u);