summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-03-08 22:07:46 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-04-08 13:24:04 +0200
commit7191b8fe38788ac57e15e4124955c3cd8333d858 (patch)
treecedf6592e8b88c5e73c352caf6fa412314839da3
parentdb797d19a3721bedc0d6b1f179e5e32621be277a (diff)
Fix some narrowing conversion warnings
ioctl call for FIONREAD takes an int arg, it won't work correctly otherwise. Cast the return of the read() call to int, because it won't read more than buffSize (which is an int). Change-Id: I130202a732684257bbb0e79c9358b60a61010c46 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/global/qlogging.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify.cpp2
-rw-r--r--src/corelib/io/qiodevice.cpp2
-rw-r--r--src/corelib/io/qipaddress.cpp2
-rw-r--r--src/corelib/io/qlockfile_unix.cpp2
-rw-r--r--src/corelib/io/qprocess_unix.cpp6
-rw-r--r--src/corelib/serialization/qxmlutils.cpp2
-rw-r--r--src/corelib/text/qstring.cpp2
-rw-r--r--src/corelib/text/qstringmatcher.cpp2
-rw-r--r--src/corelib/time/qgregoriancalendar.cpp2
-rw-r--r--src/testlib/qbenchmarkperfevents.cpp3
11 files changed, 14 insertions, 13 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 82e79e5e01..faafc8cff1 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1632,7 +1632,7 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (timeFormat == "boot"_L1) {
// just print the milliseconds since the elapsed timer reference
// like the Linux kernel does
- uint ms = QDeadlineTimer::current().deadline();
+ qint64 ms = QDeadlineTimer::current().deadline();
message.append(QString::asprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000)));
#if QT_CONFIG(datestring)
} else if (timeFormat.isEmpty()) {
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp
index 3b53b490f5..a37eecfebd 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp
@@ -334,7 +334,7 @@ void QInotifyFileSystemWatcherEngine::readFromInotify()
return;
QVarLengthArray<char, 4096> buffer(buffSize);
- buffSize = read(inotifyFd, buffer.data(), buffSize);
+ buffSize = int(read(inotifyFd, buffer.data(), buffSize));
char *at = buffer.data();
char * const end = at + buffSize;
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 29752c8e4c..81c2bc1695 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -1500,7 +1500,7 @@ qint64 QIODevice::readLineData(char *data, qint64 maxSize)
Q_D(QIODevice);
qint64 readSoFar = 0;
char c;
- int lastReadReturn = 0;
+ qint64 lastReadReturn = 0;
d->baseReadLineDataCalled = true;
while (readSoFar < maxSize && (lastReadReturn = read(&c, 1)) == 1) {
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index 9956f03738..c2b274f8b5 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -61,7 +61,7 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL
return false;
auto [ll, used] = qstrntoull(ptr, stop - ptr, 0);
- quint32 x = ll;
+ const quint32 x = quint32(ll);
if (used <= 0 || ll != x)
return false;
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index 34aa3b65ec..47aff8b973 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -170,7 +170,7 @@ bool QLockFilePrivate::removeStaleLock()
bool QLockFilePrivate::isProcessRunning(qint64 pid, const QString &appname)
{
- if (::kill(pid, 0) == -1 && errno == ESRCH)
+ if (::kill(pid_t(pid), 0) == -1 && errno == ESRCH)
return false; // PID doesn't exist anymore
const QString processName = processNameByPid(pid);
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 27c1403226..24c5ebc6d2 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -95,8 +95,8 @@ struct AutoPipe
struct ChildError
{
- qint64 code;
- char function[8];
+ int code;
+ char function[12];
};
// Used for argv and envp arguments to execve()
@@ -568,7 +568,7 @@ bool QProcessPrivate::processStarted(QString *errorMessage)
Q_Q(QProcess);
ChildError buf;
- int ret = qt_safe_read(childStartedPipe[0], &buf, sizeof(buf));
+ ssize_t ret = qt_safe_read(childStartedPipe[0], &buf, sizeof(buf));
if (stateNotifier) {
stateNotifier->setEnabled(false);
diff --git a/src/corelib/serialization/qxmlutils.cpp b/src/corelib/serialization/qxmlutils.cpp
index 00a1121280..e6fae7c173 100644
--- a/src/corelib/serialization/qxmlutils.cpp
+++ b/src/corelib/serialization/qxmlutils.cpp
@@ -48,7 +48,7 @@ bool QXmlUtils::rangeContains(RangeIter begin, RangeIter end, const QChar c)
return cp >= begin->min;
while (begin != end) {
- int delta = (end - begin) / 2;
+ qptrdiff delta = (end - begin) / 2;
RangeIter mid = begin + delta;
if (mid->min > cp)
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 64ad2c537b..ab76aadd1d 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -981,7 +981,7 @@ Q_CORE_EXPORT void qt_from_latin1(char16_t *dst, const char *str, size_t size) n
return;
} else {
size = size % 4;
- return UnrollTailLoop<3>::exec(qsizetype(size), [=](int i) { dst[i] = (uchar)str[i]; });
+ return UnrollTailLoop<3>::exec(qsizetype(size), [=](qsizetype i) { dst[i] = uchar(str[i]); });
}
# endif
#endif
diff --git a/src/corelib/text/qstringmatcher.cpp b/src/corelib/text/qstringmatcher.cpp
index 39fd45cfff..ac66ec802e 100644
--- a/src/corelib/text/qstringmatcher.cpp
+++ b/src/corelib/text/qstringmatcher.cpp
@@ -13,7 +13,7 @@ static void bm_init_skiptable(QStringView needle, uchar *skiptable, Qt::CaseSens
const char16_t *uc = needle.utf16();
const qsizetype len =
cs == Qt::CaseSensitive ? needle.size() : qMin(needle.size(), FoldBufferCapacity);
- qsizetype l = qMin(len, qsizetype(255));
+ int l = qMin(int(len), 255);
memset(skiptable, l, 256 * sizeof(uchar));
uc += len - l;
if (cs == Qt::CaseSensitive) {
diff --git a/src/corelib/time/qgregoriancalendar.cpp b/src/corelib/time/qgregoriancalendar.cpp
index 69a3665eee..1a4d3e5569 100644
--- a/src/corelib/time/qgregoriancalendar.cpp
+++ b/src/corelib/time/qgregoriancalendar.cpp
@@ -93,7 +93,7 @@ bool QGregorianCalendar::validParts(int year, int month, int day)
int QGregorianCalendar::weekDayOfJulian(qint64 jd)
{
- return qMod<7>(jd) + 1;
+ return int(qMod<7>(jd) + 1);
}
bool QGregorianCalendar::dateToJulianDay(int year, int month, int day, qint64 *jd) const
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp
index 1b9101e854..c161879a7d 100644
--- a/src/testlib/qbenchmarkperfevents.cpp
+++ b/src/testlib/qbenchmarkperfevents.cpp
@@ -108,7 +108,8 @@ static QList<PerfEvent> defaultCounters()
static int perf_event_open(perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags)
{
#ifdef SYS_perf_event_open
- return syscall(SYS_perf_event_open, attr, pid, cpu, group_fd, flags);
+ // syscall() returns long, but perf_event_open() is used to get a file descriptor
+ return int(syscall(SYS_perf_event_open, attr, pid, cpu, group_fd, flags));
#else
Q_UNUSED(attr);
Q_UNUSED(pid);