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>
This commit is contained in:
Ahmad Samir 2023-03-08 22:07:46 +02:00
parent db797d19a3
commit 7191b8fe38
11 changed files with 14 additions and 13 deletions

View File

@ -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()) {

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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);