diff options
author | Hou Lei <houlei@uniontech.com> | 2021-02-08 11:48:23 +0800 |
---|---|---|
committer | Hou Lei <houlei@uniontech.com> | 2021-02-09 10:27:14 +0800 |
commit | 841e63cb77094a7a50fe7c9f0e210b045f7c7402 (patch) | |
tree | 4bf332911c11f45d6919b5e2edd61d9348df8557 | |
parent | ff510b98d99a45880cf89b9949175ceda5f084c5 (diff) |
Canonical pointer usage
Other affected rows have also been fixed.
Change-Id: Ie0a32f724bd2e40e7bfacfaa43a78190b58e4a21
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r-- | src/corelib/text/qunicodetools.cpp | 6 | ||||
-rw-r--r-- | src/gui/painting/qregion.cpp | 12 | ||||
-rw-r--r-- | src/plugins/platforms/vnc/qvnc.cpp | 66 | ||||
-rw-r--r-- | src/testlib/qasciikey.cpp | 2 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 6 | ||||
-rw-r--r-- | src/widgets/dialogs/qfontdialog.cpp | 2 |
6 files changed, 47 insertions, 47 deletions
diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp index baf8153ea2..13a7a78e2c 100644 --- a/src/corelib/text/qunicodetools.cpp +++ b/src/corelib/text/qunicodetools.cpp @@ -1346,11 +1346,11 @@ static void to_tis620(const char16_t *string, qsizetype len, char *cstr) for (i = 0; i < len; ++i) { if (string[i] <= 0xa0) - result[i] = (unsigned char)string[i]; + result[i] = static_cast<unsigned char>(string[i]); else if (string[i] >= 0xe01 && string[i] <= 0xe5b) - result[i] = (unsigned char)(string[i] - 0xe00 + 0xa0); + result[i] = static_cast<unsigned char>(string[i] - 0xe00 + 0xa0); else - result[i] = (unsigned char)~0; // Same encoding as libthai uses for invalid chars + result[i] = static_cast<unsigned char>(~0); // Same encoding as libthai uses for invalid chars } result[len] = 0; diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index df1f2575fe..1e0ce30528 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -300,7 +300,7 @@ void QRegion::exec(const QByteArray &buffer, int ver, QDataStream::ByteOrder byt quint32 n; s >> n; QRect r; - for (int i=0; i<(int)n; i++) { + for (int i=0; i < static_cast<int>(n); i++) { s >> r; rgn = rgn.united(QRegion(r)); } @@ -349,19 +349,19 @@ QDataStream &operator<<(QDataStream &s, const QRegion &r) { auto b = r.begin(), e = r.end(); if (b == e) { - s << (quint32)0; + s << static_cast<quint32>(0); } else { const auto size = e - b; if (s.version() == 1) { for (auto i = size - 1; i > 0; --i) { - s << (quint32)(12 + i * 24); - s << (int)QRGN_OR; + s << static_cast<quint32>(12 + i * 24); + s << static_cast<int>(QRGN_OR); } for (auto it = b; it != e; ++it) - s << (quint32)(4+8) << (int)QRGN_SETRECT << *it; + s << static_cast<quint32>(4+8) << static_cast<int>(QRGN_SETRECT) << *it; } else { s << quint32(4 + 4 + 16 * size); // 16: storage size of QRect - s << (qint32)QRGN_RECTS; + s << static_cast<qint32>(QRGN_RECTS); s << quint32(size); for (auto it = b; it != e; ++it) s << *it; diff --git a/src/plugins/platforms/vnc/qvnc.cpp b/src/plugins/platforms/vnc/qvnc.cpp index 94541508eb..2782c4794a 100644 --- a/src/plugins/platforms/vnc/qvnc.cpp +++ b/src/plugins/platforms/vnc/qvnc.cpp @@ -245,7 +245,7 @@ static const struct { void QRfbRect::read(QTcpSocket *s) { quint16 buf[4]; - s->read((char*)buf, 8); + s->read(reinterpret_cast<char*>(buf), 8); x = ntohs(buf[0]); y = ntohs(buf[1]); w = ntohs(buf[2]); @@ -259,7 +259,7 @@ void QRfbRect::write(QTcpSocket *s) const buf[1] = htons(y); buf[2] = htons(w); buf[3] = htons(h); - s->write((char*)buf, 8); + s->write(reinterpret_cast<char*>(buf) , 8); } void QRfbPixelFormat::read(QTcpSocket *s) @@ -271,15 +271,15 @@ void QRfbPixelFormat::read(QTcpSocket *s) bigEndian = buf[2]; trueColor = buf[3]; - quint16 a = ntohs(*(quint16 *)(buf + 4)); + quint16 a = ntohs(*reinterpret_cast<quint16 *>(buf + 4)); redBits = 0; while (a) { a >>= 1; redBits++; } - a = ntohs(*(quint16 *)(buf + 6)); + a = ntohs(*reinterpret_cast<quint16 *>(buf + 6)); greenBits = 0; while (a) { a >>= 1; greenBits++; } - a = ntohs(*(quint16 *)(buf + 8)); + a = ntohs(*reinterpret_cast<quint16 *>(buf + 8)); blueBits = 0; while (a) { a >>= 1; blueBits++; } @@ -298,15 +298,15 @@ void QRfbPixelFormat::write(QTcpSocket *s) quint16 a = 0; for (int i = 0; i < redBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 4) = htons(a); + *reinterpret_cast<quint16 *>(buf + 4) = htons(a); a = 0; for (int i = 0; i < greenBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 6) = htons(a); + *reinterpret_cast<quint16 *>(buf + 6) = htons(a); a = 0; for (int i = 0; i < blueBits; i++) a = (a << 1) | 1; - *(quint16 *)(buf + 8) = htons(a); + *reinterpret_cast<quint16 *>(buf + 8) = htons(a); buf[10] = redShift; buf[11] = greenShift; @@ -324,14 +324,14 @@ void QRfbServerInit::setName(const char *n) void QRfbServerInit::read(QTcpSocket *s) { - s->read((char *)&width, 2); + s->read(reinterpret_cast<char *>(&width), 2); width = ntohs(width); - s->read((char *)&height, 2); + s->read(reinterpret_cast<char *>(&height), 2); height = ntohs(height); format.read(s); quint32 len; - s->read((char *)&len, 4); + s->read(reinterpret_cast<char *>(&len), 4); len = ntohl(len); name = new char [len + 1]; @@ -342,14 +342,14 @@ void QRfbServerInit::read(QTcpSocket *s) void QRfbServerInit::write(QTcpSocket *s) { quint16 t = htons(width); - s->write((char *)&t, 2); + s->write(reinterpret_cast<char *>(&t), 2); t = htons(height); - s->write((char *)&t, 2); + s->write(reinterpret_cast<char *>(&t), 2); format.write(s); - quint32 len = strlen(name); + quint32 len = static_cast<quint32>(strlen(name)); len = htonl(len); - s->write((char *)&len, 4); - s->write(name, strlen(name)); + s->write(reinterpret_cast<char *>(&len), 4); + s->write(name, static_cast<qint64>(strlen(name))); } bool QRfbSetEncodings::read(QTcpSocket *s) @@ -359,7 +359,7 @@ bool QRfbSetEncodings::read(QTcpSocket *s) char tmp; s->read(&tmp, 1); // padding - s->read((char *)&count, 2); + s->read(reinterpret_cast<char *>(&count), 2); count = ntohs(count); return true; @@ -383,17 +383,17 @@ bool QRfbKeyEvent::read(QTcpSocket *s) s->read(&down, 1); quint16 tmp; - s->read((char *)&tmp, 2); // padding + s->read(reinterpret_cast<char *>(&tmp), 2); // padding quint32 key; - s->read((char *)&key, 4); + s->read(reinterpret_cast<char *>(&key), 4); key = ntohl(key); unicode = 0; keycode = 0; int i = 0; while (keyMap[i].keysym && !keycode) { - if (keyMap[i].keysym == (int)key) + if (keyMap[i].keysym == static_cast<int>(key)) keycode = keyMap[i].keycode; i++; } @@ -430,9 +430,9 @@ bool QRfbPointerEvent::read(QTcpSocket *s) buttons |= Qt::RightButton; quint16 tmp; - s->read((char *)&tmp, 2); + s->read(reinterpret_cast<char *>(&tmp), 2); x = ntohs(tmp); - s->read((char *)&tmp, 2); + s->read(reinterpret_cast<char *>(&tmp), 2); y = ntohs(tmp); return true; @@ -445,7 +445,7 @@ bool QRfbClientCutText::read(QTcpSocket *s) char tmp[3]; s->read(tmp, 3); // padding - s->read((char *)&length, 4); + s->read(reinterpret_cast<char *>(&length), 4); length = ntohl(length); return true; @@ -486,7 +486,7 @@ void QRfbRawEncoder::write() { const quint16 count = htons(rectsInRegion); - socket->write((char *)&count, sizeof(count)); + socket->write(reinterpret_cast<const char *>(&count), sizeof(count)); } if (rectsInRegion <= 0) @@ -500,7 +500,7 @@ void QRfbRawEncoder::write() rect.write(socket); const quint32 encoding = htonl(0); // raw encoding - socket->write((char *)&encoding, sizeof(encoding)); + socket->write(reinterpret_cast<const char *>(&encoding), sizeof(encoding)); qsizetype linestep = screenImage.bytesPerLine(); const uchar *screendata = screenImage.scanLine(rect.y) @@ -516,14 +516,14 @@ void QRfbRawEncoder::write() const int bstep = rect.w * bytesPerPixel; const int depth = screenImage.depth(); for (int i = 0; i < rect.h; ++i) { - client->convertPixels(b, (const char*)screendata, rect.w, depth); + client->convertPixels(b, reinterpret_cast<const char*>(screendata), rect.w, depth); screendata += linestep; b += bstep; } socket->write(buffer.constData(), bufferSize); } else { for (int i = 0; i < rect.h; ++i) { - socket->write((const char*)screendata, rect.w * bytesPerPixel); + socket->write(reinterpret_cast<const char*>(screendata), rect.w * bytesPerPixel); screendata += linestep; } } @@ -553,13 +553,13 @@ void QVncClientCursor::write(QVncClient *client) const { const quint16 tmp[6] = { htons(0), htons(1), - htons(uint16_t(hotspot.x())), htons(uint16_t(hotspot.y())), - htons(uint16_t(cursor.width())), - htons(uint16_t(cursor.height())) }; - socket->write((char*)tmp, sizeof(tmp)); + htons(static_cast<uint16_t>(hotspot.x())), htons(static_cast<uint16_t>(hotspot.y())), + htons(static_cast<uint16_t>(cursor.width())), + htons(static_cast<uint16_t>(cursor.height())) }; + socket->write(reinterpret_cast<const char*>(tmp), sizeof(tmp)); const qint32 encoding = qToBigEndian(-239); - socket->write((char*)(&encoding), sizeof(encoding)); + socket->write(reinterpret_cast<const char*>(&encoding), sizeof(encoding)); } if (cursor.isNull()) @@ -583,7 +583,7 @@ void QVncClientCursor::write(QVncClient *client) const Q_ASSERT(bitmap.size() == img.size()); const int width = (bitmap.width() + 7) / 8; for (int i = 0; i < bitmap.height(); ++i) - socket->write((const char*)bitmap.scanLine(i), width); + socket->write(reinterpret_cast<const char*>(bitmap.scanLine(i)), width); } void QVncClientCursor::changeCursor(QCursor *widgetCursor, QWindow *window) diff --git a/src/testlib/qasciikey.cpp b/src/testlib/qasciikey.cpp index 9a308da2bc..28404ec37d 100644 --- a/src/testlib/qasciikey.cpp +++ b/src/testlib/qasciikey.cpp @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE */ Qt::Key QTest::asciiToKey(char ascii) { - switch ((unsigned char)ascii) { + switch (static_cast<unsigned char>(ascii)) { case 0x08: return Qt::Key_Backspace; case 0x09: return Qt::Key_Tab; case 0x0b: return Qt::Key_Backtab; diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 7c2de877da..17901eb08a 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -227,7 +227,7 @@ static void stackTrace() "detach\n" "quit\n" "EOF\n", - (int)getpid()); + static_cast<int>(getpid())); if (system(cmd) == -1) fprintf(stderr, "calling gdb failed\n"); fprintf(stderr, "=== End of stack trace ===\n"); @@ -237,7 +237,7 @@ static void stackTrace() "bt all\n" "quit\n" "EOF\n", - (int)getpid()); + static_cast<int>(getpid())); if (system(cmd) == -1) fprintf(stderr, "calling lldb failed\n"); fprintf(stderr, "=== End of stack trace ===\n"); @@ -502,7 +502,7 @@ static void qPrintDataTags(FILE *stream) static int qToInt(const char *str) { char *pEnd; - int l = (int)strtol(str, &pEnd, 10); + int l = static_cast<int>(strtol(str, &pEnd, 10)); if (*pEnd != 0) { fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); exit(1); diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index 6e7253b789..3a835641df 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -575,7 +575,7 @@ void QFontDialogPrivate::updateStyles() QString cstyle = style; redo: - for (int i = 0; i < (int)styleList->count(); i++) { + for (int i = 0; i < static_cast<int>(styleList->count()); i++) { if (cstyle == styleList->text(i)) { styleList->setCurrentItem(i); found = true; |