diff options
author | Robert Griebl <robert.griebl@qt.io> | 2019-11-08 12:14:22 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2019-11-08 15:40:13 +0100 |
commit | 3da065412d74d55eea9d28034f5eab10fe5c72ab (patch) | |
tree | fcbf98815c0c792df4f4d972bf468a46d38db5a8 | |
parent | 203e03e16688ea47274c60ec1b637ff2e8ab0655 (diff) |
Fix compiler and code-model warnings
Change-Id: I3bdc402537bd284b70e03fc88fc30840d681a320
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r-- | src/application-lib/yamlpackagescanner.cpp | 2 | ||||
-rw-r--r-- | src/common-lib/qtyaml.cpp | 195 | ||||
-rw-r--r-- | src/common-lib/startuptimer.cpp | 25 | ||||
-rw-r--r-- | src/main-lib/configuration.cpp | 4 | ||||
-rw-r--r-- | src/main-lib/configuration.h | 2 | ||||
-rw-r--r-- | src/monitor-lib/processreader.cpp | 19 | ||||
-rw-r--r-- | src/monitor-lib/sysfsreader.cpp | 9 | ||||
-rw-r--r-- | src/monitor-lib/systemreader.cpp | 14 | ||||
-rw-r--r-- | src/package-lib/packagecreator.cpp | 2 | ||||
-rw-r--r-- | src/tools/appman/appman.cpp | 1 | ||||
-rw-r--r-- | src/window-lib/windowmanager.cpp | 1 | ||||
-rw-r--r-- | tests/applicationinstaller/tst_applicationinstaller.cpp | 4 | ||||
-rw-r--r-- | tests/main/tst_main.cpp | 6 |
13 files changed, 48 insertions, 236 deletions
diff --git a/src/application-lib/yamlpackagescanner.cpp b/src/application-lib/yamlpackagescanner.cpp index 4cb6ea4e..f6a569fe 100644 --- a/src/application-lib/yamlpackagescanner.cpp +++ b/src/application-lib/yamlpackagescanner.cpp @@ -291,7 +291,7 @@ PackageInfo *YamlPackageScanner::scan(QIODevice *source, const QString &fileName .arg(intentInfo->m_id).arg(visibilityStr); } }); - intentFields.emplace_back(legacy ? "handledBy" : "handlingApplicationId", false, YamlParser::Scalar, [&pkgInfo, &intentInfo, &appIds](YamlParser *p) { + intentFields.emplace_back(legacy ? "handledBy" : "handlingApplicationId", false, YamlParser::Scalar, [&intentInfo, &appIds](YamlParser *p) { QString appId = p->parseString(); if (appIds.contains(appId)) { intentInfo->m_handlingApplicationId = appId; diff --git a/src/common-lib/qtyaml.cpp b/src/common-lib/qtyaml.cpp index 47d973f7..f6a625ac 100644 --- a/src/common-lib/qtyaml.cpp +++ b/src/common-lib/qtyaml.cpp @@ -60,201 +60,6 @@ QT_BEGIN_NAMESPACE_AM namespace QtYaml { -static QVariant convertYamlNodeToVariant(yaml_document_t *doc, yaml_node_t *node) -{ - QVariant result; - - if (!doc) - return result; - if (!node) - return result; - - switch (node->type) { - case YAML_SCALAR_NODE: { - const QByteArray ba = QByteArray::fromRawData(reinterpret_cast<const char *>(node->data.scalar.value), - int(node->data.scalar.length)); - - if (node->data.scalar.style == YAML_SINGLE_QUOTED_SCALAR_STYLE - || node->data.scalar.style == YAML_DOUBLE_QUOTED_SCALAR_STYLE) { - result = QString::fromUtf8(ba); - break; - } - - enum ValueIndex { - ValueNull, - ValueTrue, - ValueFalse, - ValueNaN, - ValueInf - }; - - struct StaticMapping - { - const char *text; - ValueIndex index; - }; - - static QVariant staticValues[] = { - QVariant(), // ValueNull - QVariant(true), // ValueTrue - QVariant(false), // ValueFalse - QVariant(qQNaN()), // ValueNaN - QVariant(qInf()), // ValueInf - }; - - static const StaticMapping staticMappings[] = { // keep this sorted for bsearch !! - { "", ValueNull }, - { ".INF", ValueInf }, - { ".Inf", ValueInf }, - { ".NAN", ValueNaN }, - { ".NaN", ValueNaN }, - { ".inf", ValueInf }, - { ".nan", ValueNaN }, - { "FALSE", ValueFalse }, - { "False", ValueFalse }, - { "N", ValueFalse }, - { "NO", ValueFalse }, - { "NULL", ValueNull }, - { "No", ValueFalse }, - { "Null", ValueNull }, - { "OFF", ValueFalse }, - { "Off", ValueFalse }, - { "ON", ValueTrue }, - { "On", ValueTrue }, - { "TRUE", ValueTrue }, - { "True", ValueTrue }, - { "Y", ValueTrue }, - { "YES", ValueTrue }, - { "Yes", ValueTrue }, - { "false", ValueFalse }, - { "n", ValueFalse }, - { "no", ValueFalse }, - { "null", ValueNull }, - { "off", ValueFalse }, - { "on", ValueTrue }, - { "true", ValueTrue }, - { "y", ValueTrue }, - { "yes", ValueTrue }, - { "~", ValueNull } - }; - - static const char *firstCharStaticMappings = ".FNOTYfnoty~"; - char firstChar = ba.isEmpty() ? 0 : ba.at(0); - - if (strchr(firstCharStaticMappings, firstChar)) { // cheap check to avoid expensive bsearch - StaticMapping key { ba.constData(), ValueNull }; - auto found = bsearch(&key, - staticMappings, - sizeof(staticMappings)/sizeof(staticMappings[0]), - sizeof(staticMappings[0]), - [](const void *m1, const void *m2) { - return strcmp(static_cast<const StaticMapping *>(m1)->text, - static_cast<const StaticMapping *>(m2)->text); }); - - if (found) { - result = staticValues[static_cast<StaticMapping *>(found)->index]; - break; - } - } - - QString str = QString::fromUtf8(ba); - result = str; - - if ((firstChar >= '0' && firstChar <= '9') // cheap check to avoid expensive regexps - || firstChar == '+' || firstChar == '-' || firstChar == '.') { - static const QRegExp numberRegExps[] = { - QRegExp(qSL("[-+]?0b[0-1_]+")), // binary - QRegExp(qSL("[-+]?0x[0-9a-fA-F_]+")), // hexadecimal - QRegExp(qSL("[-+]?0[0-7_]+")), // octal - QRegExp(qSL("[-+]?(0|[1-9][0-9_]*)")), // decimal - QRegExp(qSL("[-+]?([0-9][0-9_]*)?\\.[0-9.]*([eE][-+][0-9]+)?")), // float - QRegExp() - }; - - for (int numberIndex = 0; !numberRegExps[numberIndex].isEmpty(); ++numberIndex) { - if (numberRegExps[numberIndex].exactMatch(str)) { - bool ok = false; - QVariant val; - - // YAML allows _ as a grouping separator - if (str.contains(qL1C('_'))) - str = str.replace(qL1C('_'), qSL("")); - - if (numberIndex == 4) { - val = str.toDouble(&ok); - } else { - int base = 10; - - switch (numberIndex) { - case 0: base = 2; str.replace(qSL("0b"), qSL("")); break; // Qt chokes on 0b - case 1: base = 16; break; - case 2: base = 8; break; - case 3: base = 10; break; - } - - qint64 s64 = str.toLongLong(&ok, base); - if (ok && (s64 <= std::numeric_limits<qint32>::max())) { - val = qint32(s64); - } else if (ok) { - val = s64; - } else { - quint64 u64 = str.toULongLong(&ok, base); - - if (ok && (u64 <= std::numeric_limits<quint32>::max())) - val = quint32(u64); - else if (ok) - val = u64; - } - } - if (ok) { - result = val; - break; - } - } - } - } - break; - } - case YAML_SEQUENCE_NODE: { - QVariantList array; - for (auto seq = node->data.sequence.items.start; seq < node->data.sequence.items.top; ++seq) { - yaml_node_t *seqNode = yaml_document_get_node(doc, *seq); - if (seqNode) - array.append(convertYamlNodeToVariant(doc, seqNode)); - else - array.append(QVariant()); - } - result = array; - break; - } - case YAML_MAPPING_NODE: { - QVariantMap object; - for (auto map = node->data.mapping.pairs.start; map < node->data.mapping.pairs.top; ++map) { - yaml_node_t *keyNode = yaml_document_get_node(doc, map->key); - yaml_node_t *valueNode = yaml_document_get_node(doc, map->value); - if (keyNode && valueNode) { - QVariant key = convertYamlNodeToVariant(doc, keyNode); - QString keyStr = key.toString(); - - if (key.type() != QVariant::String) - qWarning() << "YAML Parser: converting non-string mapping key to string for JSON compatibility"; - if (object.contains(keyStr)) - qWarning() << "YAML Parser: duplicate key" << keyStr << "found in mapping"; - - object.insert(keyStr, convertYamlNodeToVariant(doc, valueNode)); - } - } - result = object; - break; - } - default: - break; - } - - return result; -} - - static inline void yerr(int result) Q_DECL_NOEXCEPT_EXPR(false) { if (!result) diff --git a/src/common-lib/startuptimer.cpp b/src/common-lib/startuptimer.cpp index f007166b..5e143093 100644 --- a/src/common-lib/startuptimer.cpp +++ b/src/common-lib/startuptimer.cpp @@ -329,14 +329,15 @@ StartupTimer::StartupTimer() size_t procInfoSize; if (sysctl(mibNames, sizeof(mibNames) / sizeof(mibNames[0]), nullptr, &procInfoSize, nullptr, 0) == 0) { - kinfo_proc *procInfo = (kinfo_proc *) malloc(procInfoSize); + kinfo_proc *procInfo = static_cast<kinfo_proc *>(malloc(procInfoSize)); if (sysctl(mibNames, sizeof(mibNames) / sizeof(mibNames[0]), procInfo, &procInfoSize, nullptr, 0) == 0) { struct timeval now; if (gettimeofday(&now, nullptr) == 0) { - m_processCreation = (quint64(now.tv_sec) * 1000000 + now.tv_usec) - - (procInfo->kp_proc.p_un.__p_starttime.tv_sec * 1000000 + procInfo->kp_proc.p_un.__p_starttime.tv_usec); + m_processCreation = (quint64(now.tv_sec) * 1000000 + quint64(now.tv_usec)) + - (quint64(procInfo->kp_proc.p_un.__p_starttime.tv_sec) * 1000000 + + quint64(procInfo->kp_proc.p_un.__p_starttime.tv_usec)); m_initialized = true; } } else { @@ -353,7 +354,7 @@ StartupTimer::StartupTimer() size_t bootTimeLen = sizeof(bootTime); int mibNames[2] = { CTL_KERN, KERN_BOOTTIME }; if (sysctl(mibNames, sizeof(mibNames) / sizeof(mibNames[0]), &bootTime, &bootTimeLen, nullptr, 0) == 0 ) { - m_systemUpTime = (time(nullptr) - bootTime.tv_sec) * 1000; // we don't need more precision on macOS + m_systemUpTime = quint64(time(nullptr) - bootTime.tv_sec) * 1000; // we don't need more precision on macOS emit systemUpTimeChanged(m_systemUpTime); } } @@ -450,10 +451,9 @@ void StartupTimer::createReport(const QString &title) if (m_output == stderr) getOutputInformation(&ansiColorSupport, nullptr, nullptr); - const char *format = "\n== STARTUP TIMING REPORT: %s ==\n"; - if (ansiColorSupport) - format = "\n\033[33m== STARTUP TIMING REPORT: %s ==\033[0m\n"; - fprintf(m_output, format, title.toLocal8Bit().data()); + constexpr const char *plainFormat = "\n== STARTUP TIMING REPORT: %s ==\n"; + constexpr const char *colorFormat = "\n\033[33m== STARTUP TIMING REPORT: %s ==\033[0m\n"; + fprintf(m_output, ansiColorSupport ? colorFormat : plainFormat, title.toLocal8Bit().data()); static const int barCols = 60; @@ -475,12 +475,11 @@ void StartupTimer::createReport(const QString &title) QByteArray spacing(maxTextLen - text.length(), ' '); SplitSeconds ss = splitMicroSecs(usec); - const char *format = "%d'%03d.%03d %s %s#%s\n"; - if (ansiColorSupport) - format = "\033[32m%d'%03d.%03d\033[0m %s %s\033[44m %s\033[0m\n"; + constexpr const char *plainFormat = "%d'%03d.%03d %s %s#%s\n"; + constexpr const char *colorFormat = "\033[32m%d'%03d.%03d\033[0m %s %s\033[44m %s\033[0m\n"; - fprintf(m_output, format, ss.sec, ss.msec, ss.usec, - text.constData(), spacing.constData(), bar.constData()); + fprintf(m_output, ansiColorSupport ? colorFormat : plainFormat, + ss.sec, ss.msec, ss.usec, text.constData(), spacing.constData(), bar.constData()); } fflush(m_output); diff --git a/src/main-lib/configuration.cpp b/src/main-lib/configuration.cpp index 26a58dd5..5df06fa9 100644 --- a/src/main-lib/configuration.cpp +++ b/src/main-lib/configuration.cpp @@ -733,8 +733,8 @@ ConfigurationData *ConfigurationData::loadFromSource(QIODevice *source, const QS p->parseFields({ { "builtinAppsManifestDir", false, YamlParser::Scalar | YamlParser::List, [&cd](YamlParser *p) { cd->applications.builtinAppsManifestDir = p->parseStringOrStringList(); } }, - { "installedAppsManifestDir", false, YamlParser::Scalar | YamlParser::List, [&cd](YamlParser *) { - /* deprecated - ignore */ } }, + { "installedAppsManifestDir", false, YamlParser::Scalar, [](YamlParser *p) { + (void) p->parseScalar(); /* deprecated - ignore */ } }, { "installationDir", false, YamlParser::Scalar | YamlParser::Scalar, [&cd](YamlParser *p) { cd->applications.installationDir = p->parseScalar().toString(); } }, { "documentDir", false, YamlParser::Scalar | YamlParser::Scalar, [&cd](YamlParser *p) { diff --git a/src/main-lib/configuration.h b/src/main-lib/configuration.h index dc4a04a1..7c950a57 100644 --- a/src/main-lib/configuration.h +++ b/src/main-lib/configuration.h @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE_AM -class ConfigurationData; +struct ConfigurationData; class Configuration { diff --git a/src/monitor-lib/processreader.cpp b/src/monitor-lib/processreader.cpp index 6cbbe22d..aacde41f 100644 --- a/src/monitor-lib/processreader.cpp +++ b/src/monitor-lib/processreader.cpp @@ -50,13 +50,6 @@ # include <unistd.h> #endif -namespace { - static uint parseValue(const char *pl) { - while (*pl && (*pl < '0' || *pl > '9')) - pl++; - return static_cast<uint>(strtoul(pl, nullptr, 10)); - } -} QT_USE_NAMESPACE_AM @@ -71,8 +64,7 @@ void ProcessReader::update() { // read cpu { - qreal cpuLoadFloat = readCpuLoad(); - quint32 value = ((qreal)std::numeric_limits<quint32>::max()) * cpuLoadFloat; + quint32 value = quint32(readCpuLoad() * std::numeric_limits<quint32>::max()); cpuLoad.store(value); } @@ -95,6 +87,12 @@ void ProcessReader::update() #if defined(Q_OS_LINUX) +static uint parseValue(const char *pl) { + while (*pl && (*pl < '0' || *pl > '9')) + pl++; + return static_cast<uint>(strtoul(pl, nullptr, 10)); +} + void ProcessReader::openCpuLoad() { const QByteArray fileName = "/proc/" + QByteArray::number(m_pid) + "/stat"; @@ -345,7 +343,8 @@ bool ProcessReader::readMemory() struct task_basic_info t_info; mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; - if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count)) { + if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, + reinterpret_cast<task_info_t>(&t_info), &t_info_count)) { qCWarning(LogSystem) << "Could not read memory data"; return false; } diff --git a/src/monitor-lib/sysfsreader.cpp b/src/monitor-lib/sysfsreader.cpp index 2b6e66a1..3465b623 100644 --- a/src/monitor-lib/sysfsreader.cpp +++ b/src/monitor-lib/sysfsreader.cpp @@ -44,7 +44,7 @@ #include <qplatformdefs.h> #include "sysfsreader.h" -# define EINTR_LOOP(cmd) __extension__ ({__typeof__(cmd) res = 0; do { res = cmd; } while (res == -1 && errno == EINTR); res; }) +#define EINTR_LOOP(cmd) __extension__ ({__typeof__(cmd) res = 0; do { res = cmd; } while (res == -1 && errno == EINTR); res; }) static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777) { @@ -56,8 +56,9 @@ static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 07 ::fcntl(fd, F_SETFD, FD_CLOEXEC); return fd; } -# undef QT_OPEN -# define QT_OPEN qt_safe_open + +#undef QT_OPEN +#define QT_OPEN qt_safe_open QT_BEGIN_NAMESPACE_AM @@ -94,7 +95,7 @@ QByteArray SysFsReader::readValue() const int offset = 0; int read = 0; do { - read = static_cast<int>(EINTR_LOOP(QT_READ(m_fd, m_buffer.data() + offset, m_buffer.size() - offset))); + read = int(EINTR_LOOP(QT_READ(m_fd, m_buffer.data() + offset, size_t(m_buffer.size() - offset)))); if (read < 0) return QByteArray(); else if (read < (m_buffer.size() - offset)) diff --git a/src/monitor-lib/systemreader.cpp b/src/monitor-lib/systemreader.cpp index bc1c8514..3feaa813 100644 --- a/src/monitor-lib/systemreader.cpp +++ b/src/monitor-lib/systemreader.cpp @@ -686,8 +686,9 @@ qreal CpuReader::readLoadValue() mach_msg_type_number_t cpuLoadInfoCount = 0; if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpuCount, - (processor_info_array_t *) &cpuLoadInfo, &cpuLoadInfoCount) == KERN_SUCCESS) { - uint64_t idle = 0, total = 0; + reinterpret_cast<processor_info_array_t *>(&cpuLoadInfo), + &cpuLoadInfoCount) == KERN_SUCCESS) { + qint64 idle = 0, total = 0; for (natural_t i = 0; i < cpuCount; ++i) { idle += cpuLoadInfo[i].cpu_ticks[CPU_STATE_IDLE]; @@ -696,7 +697,7 @@ qreal CpuReader::readLoadValue() + cpuLoadInfo[i].cpu_ticks[CPU_STATE_IDLE] \ + cpuLoadInfo[i].cpu_ticks[CPU_STATE_NICE]; } - vm_deallocate(mach_task_self(), (vm_address_t) cpuLoadInfo, cpuLoadInfoCount); + vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(cpuLoadInfo), cpuLoadInfoCount); m_load = qreal(1) - (qreal(idle - m_lastIdle) / qreal(total - m_lastTotal)); @@ -719,7 +720,7 @@ MemoryReader::MemoryReader() size_t hwMemSize = sizeof(hwMem); if (sysctl(mib, sizeof(mib) / sizeof(*mib), &hwMem, &hwMemSize, nullptr, 0) == KERN_SUCCESS) - s_totalValue = hwMem; + s_totalValue = quint64(hwMem); mib[1] = HW_PAGESIZE; int hwPageSize; @@ -735,12 +736,13 @@ quint64 MemoryReader::readUsedValue() const vm_statistics64_data_t vmStat; mach_msg_type_number_t vmStatCount = HOST_VM_INFO64_COUNT; - if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) &vmStat, &vmStatCount) == KERN_SUCCESS) { + if (host_statistics64(mach_host_self(), HOST_VM_INFO64, + reinterpret_cast<host_info64_t>(&vmStat), &vmStatCount) == KERN_SUCCESS) { quint64 app = vmStat.internal_page_count; quint64 compressed = vmStat.compressor_page_count; quint64 wired = vmStat.wire_count; - return (app + compressed + wired) * s_pageSize; + return (app + compressed + wired) * quint64(s_pageSize); } else { return 0; } diff --git a/src/package-lib/packagecreator.cpp b/src/package-lib/packagecreator.cpp index ab1fd448..4a4f50c8 100644 --- a/src/package-lib/packagecreator.cpp +++ b/src/package-lib/packagecreator.cpp @@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE_AM */ static void fixed_archive_entry_set_pathname(archive_entry *entry, const QString &pathname) { - wchar_t *wchars = new wchar_t[pathname.length() + 1]; + wchar_t *wchars = new wchar_t[size_t(pathname.length()) + 1]; wchars[pathname.toWCharArray(wchars)] = 0; archive_entry_copy_pathname_w(entry, wchars); delete[] wchars; diff --git a/src/tools/appman/appman.cpp b/src/tools/appman/appman.cpp index b607a7f3..a907ee6d 100644 --- a/src/tools/appman/appman.cpp +++ b/src/tools/appman/appman.cpp @@ -43,6 +43,7 @@ #include <QQmlApplicationEngine> #include <QQmlContext> +#include <QCoreApplication> #include "global.h" #include "logging.h" diff --git a/src/window-lib/windowmanager.cpp b/src/window-lib/windowmanager.cpp index 63d93e8d..4bb3d3b5 100644 --- a/src/window-lib/windowmanager.cpp +++ b/src/window-lib/windowmanager.cpp @@ -575,6 +575,7 @@ QObject *WindowManager::addExtension(QQmlComponent *component) const return extension; #else + Q_UNUSED(component) return nullptr; #endif } diff --git a/tests/applicationinstaller/tst_applicationinstaller.cpp b/tests/applicationinstaller/tst_applicationinstaller.cpp index 89bd0224..63861d28 100644 --- a/tests/applicationinstaller/tst_applicationinstaller.cpp +++ b/tests/applicationinstaller/tst_applicationinstaller.cpp @@ -561,6 +561,10 @@ void tst_PackageManager::simulateErrorConditions_data() void tst_PackageManager::simulateErrorConditions() { +#ifndef Q_OS_LINUX + QSKIP("Only tested on Linux"); +#endif + QFETCH(bool, testUpdate); QFETCH(QString, errorString); QFETCH(FunctionMap, functions); diff --git a/tests/main/tst_main.cpp b/tests/main/tst_main.cpp index f014a6b2..090df7b7 100644 --- a/tests/main/tst_main.cpp +++ b/tests/main/tst_main.cpp @@ -179,13 +179,13 @@ void tst_Main::installPackage(const QString &pkgPath) bool installationFinished = false; connect(packageManager, &PackageManager::taskRequestingInstallationAcknowledge, - this, [this, packageManager](const QString &taskId, const QVariantMap &, + this, [packageManager](const QString &taskId, const QVariantMap &, const QVariantMap &, const QVariantMap &) { packageManager->acknowledgePackageInstallation(taskId); }); connect(packageManager, &PackageManager::taskFinished, - this, [this, &installationFinished](const QString &) { + this, [&installationFinished](const QString &) { installationFinished = true; }); @@ -201,7 +201,7 @@ void tst_Main::removePackage(const QString &id) bool removalFinished = false; connect(packageManager, &PackageManager::taskFinished, - this, [this, &removalFinished](const QString &) { + this, [&removalFinished](const QString &) { removalFinished = true; }); |