Skip to content

Commit 3fc1c91

Browse files
committed
lint: remove reinterpret_cast lint
Unhelpful.
1 parent be5e5fc commit 3fc1c91

File tree

15 files changed

+41
-72
lines changed

15 files changed

+41
-72
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Checks: >
1717
-cppcoreguidelines-avoid-goto,
1818
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
1919
-cppcoreguidelines-avoid-do-while,
20+
-cppcoreguidelines-pro-type-reinterpret-cast,
2021
google-global-names-in-headers,
2122
google-readability-casting,
2223
google-runtime-int,

src/core/logging.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,23 +485,21 @@ void WriteBuffer::writeBytes(const char* data, qsizetype length) {
485485
this->buffer.append(data, length);
486486
}
487487

488-
void WriteBuffer::writeU8(quint8 data) {
489-
this->writeBytes(reinterpret_cast<char*>(&data), 1); // NOLINT
490-
}
488+
void WriteBuffer::writeU8(quint8 data) { this->writeBytes(reinterpret_cast<char*>(&data), 1); }
491489

492490
void WriteBuffer::writeU16(quint16 data) {
493491
data = qToLittleEndian(data);
494-
this->writeBytes(reinterpret_cast<char*>(&data), 2); // NOLINT
492+
this->writeBytes(reinterpret_cast<char*>(&data), 2);
495493
}
496494

497495
void WriteBuffer::writeU32(quint32 data) {
498496
data = qToLittleEndian(data);
499-
this->writeBytes(reinterpret_cast<char*>(&data), 4); // NOLINT
497+
this->writeBytes(reinterpret_cast<char*>(&data), 4);
500498
}
501499

502500
void WriteBuffer::writeU64(quint64 data) {
503501
data = qToLittleEndian(data);
504-
this->writeBytes(reinterpret_cast<char*>(&data), 8); // NOLINT
502+
this->writeBytes(reinterpret_cast<char*>(&data), 8);
505503
}
506504

507505
void DeviceReader::setDevice(QIODevice* device) { this->device = device; }
@@ -518,19 +516,19 @@ qsizetype DeviceReader::peekBytes(char* data, qsizetype length) {
518516
bool DeviceReader::skip(qsizetype length) { return this->device->skip(length) == length; }
519517

520518
bool DeviceReader::readU8(quint8* data) {
521-
return this->readBytes(reinterpret_cast<char*>(data), 1); // NOLINT
519+
return this->readBytes(reinterpret_cast<char*>(data), 1);
522520
}
523521

524522
bool DeviceReader::readU16(quint16* data) {
525-
return this->readBytes(reinterpret_cast<char*>(data), 2); // NOLINT
523+
return this->readBytes(reinterpret_cast<char*>(data), 2);
526524
}
527525

528526
bool DeviceReader::readU32(quint32* data) {
529-
return this->readBytes(reinterpret_cast<char*>(data), 4); // NOLINT
527+
return this->readBytes(reinterpret_cast<char*>(data), 4);
530528
}
531529

532530
bool DeviceReader::readU64(quint64* data) {
533-
return this->readBytes(reinterpret_cast<char*>(data), 8); // NOLINT
531+
return this->readBytes(reinterpret_cast<char*>(data), 8);
534532
}
535533

536534
void EncodedLogWriter::setDevice(QIODevice* target) { this->buffer.setDevice(target); }
@@ -712,18 +710,18 @@ void EncodedLogWriter::writeVarInt(quint32 n) {
712710

713711
bool EncodedLogReader::readVarInt(quint32* slot) {
714712
auto bytes = std::array<quint8, 7>();
715-
auto readLength = this->reader.peekBytes(reinterpret_cast<char*>(bytes.data()), 7); // NOLINT
713+
auto readLength = this->reader.peekBytes(reinterpret_cast<char*>(bytes.data()), 7);
716714

717715
if (bytes[0] != 0xff && readLength >= 1) {
718-
auto n = *reinterpret_cast<quint8*>(bytes.data()); // NOLINT
716+
auto n = *reinterpret_cast<quint8*>(bytes.data());
719717
if (!this->reader.skip(1)) return false;
720718
*slot = qFromLittleEndian(n);
721719
} else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) {
722-
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1); // NOLINT
720+
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1);
723721
if (!this->reader.skip(3)) return false;
724722
*slot = qFromLittleEndian(n);
725723
} else if (readLength == 7) {
726-
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3); // NOLINT
724+
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3);
727725
if (!this->reader.skip(7)) return false;
728726
*slot = qFromLittleEndian(n);
729727
} else return false;

src/core/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DropEmitter {
6565
template <class O>
6666
DropEmitter(O* object, void (*signal)(O*))
6767
: object(object)
68-
, signal(*reinterpret_cast<void (*)(void*)>(signal)) {} // NOLINT
68+
, signal(*reinterpret_cast<void (*)(void*)>(signal)) {}
6969

7070
DropEmitter() = default;
7171

src/dbus/dbusmenu/dbusmenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ QQmlListProperty<QsMenuEntry> DBusMenuItem::children() {
105105
}
106106

107107
qsizetype DBusMenuItem::childrenCount(QQmlListProperty<QsMenuEntry>* property) {
108-
return reinterpret_cast<DBusMenuItem*>(property->object)->enabledChildren.count(); // NOLINT
108+
return reinterpret_cast<DBusMenuItem*>(property->object)->enabledChildren.count();
109109
}
110110

111111
QsMenuEntry* DBusMenuItem::childAt(QQmlListProperty<QsMenuEntry>* property, qsizetype index) {
112-
auto* item = reinterpret_cast<DBusMenuItem*>(property->object); // NOLINT
112+
auto* item = reinterpret_cast<DBusMenuItem*>(property->object);
113113
return item->menu->items.value(item->enabledChildren.at(index));
114114
}
115115

src/dbus/properties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QDBusError demarshallVariant(const QVariant& variant, const QMetaType& type, voi
3737

3838
if (variant.metaType() == type) {
3939
if (type.id() == QMetaType::QVariant) {
40-
*reinterpret_cast<QVariant*>(slot) = variant; // NOLINT
40+
*reinterpret_cast<QVariant*>(slot) = variant;
4141
} else {
4242
type.destruct(slot);
4343
type.construct(slot, variant.constData());

src/io/fileview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void FileViewWriter::write(
281281
if (shouldCancel.loadAcquire()) return;
282282

283283
if (doAtomicWrite) {
284-
if (!reinterpret_cast<QSaveFile*>(file.get())->commit()) { // NOLINT
284+
if (!reinterpret_cast<QSaveFile*>(file.get())->commit()) {
285285
qmlWarning(view) << "Write of " << state.path << " failed: Atomic commit failed.";
286286
}
287287
}

src/services/greetd/connection.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ void GreetdConnection::onSocketError(QLocalSocket::LocalSocketError error) {
159159
void GreetdConnection::onSocketReady() {
160160
qint32 length = 0;
161161

162-
this->socket.read(
163-
reinterpret_cast<char*>(&length), // NOLINT
164-
sizeof(qint32)
165-
);
162+
this->socket.read(reinterpret_cast<char*>(&length), sizeof(qint32));
166163

167164
auto text = this->socket.read(length);
168165
auto json = QJsonDocument::fromJson(text).object();
@@ -248,10 +245,7 @@ void GreetdConnection::sendRequest(const QJsonObject& json) {
248245
<< QJsonDocument(debugJson).toJson(QJsonDocument::Compact);
249246
}
250247

251-
this->socket.write(
252-
reinterpret_cast<char*>(&length), // NOLINT
253-
sizeof(qint32)
254-
);
248+
this->socket.write(reinterpret_cast<char*>(&length), sizeof(qint32));
255249

256250
this->socket.write(text);
257251
this->socket.flush();

src/services/notifications/dbusimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ QImage DBusNotificationImage::createImage() const {
1515
auto format = this->hasAlpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888;
1616

1717
return QImage(
18-
reinterpret_cast<const uchar*>(this->data.data()), // NOLINT
18+
reinterpret_cast<const uchar*>(this->data.data()),
1919
this->width,
2020
this->height,
2121
format

src/services/pam/conversation.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,14 @@ void PamConversation::onMessage() {
7979

8080
auto type = PamIpcEvent::Exit;
8181

82-
auto ok = this->pipes.readBytes(
83-
reinterpret_cast<char*>(&type), // NOLINT
84-
sizeof(PamIpcEvent)
85-
);
82+
auto ok = this->pipes.readBytes(reinterpret_cast<char*>(&type), sizeof(PamIpcEvent));
8683

8784
if (!ok) goto fail;
8885

8986
if (type == PamIpcEvent::Exit) {
9087
auto code = PamIpcExitCode::OtherError;
9188

92-
ok = this->pipes.readBytes(
93-
reinterpret_cast<char*>(&code), // NOLINT
94-
sizeof(PamIpcExitCode)
95-
);
89+
ok = this->pipes.readBytes(reinterpret_cast<char*>(&code), sizeof(PamIpcExitCode));
9690

9791
if (!ok) goto fail;
9892

@@ -112,10 +106,7 @@ void PamConversation::onMessage() {
112106
} else if (type == PamIpcEvent::Request) {
113107
PamIpcRequestFlags flags {};
114108

115-
ok = this->pipes.readBytes(
116-
reinterpret_cast<char*>(&flags), // NOLINT
117-
sizeof(PamIpcRequestFlags)
118-
);
109+
ok = this->pipes.readBytes(reinterpret_cast<char*>(&flags), sizeof(PamIpcRequestFlags));
119110

120111
if (!ok) goto fail;
121112

src/services/pam/ipc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::string PamIpcPipes::readString(bool* ok) const {
4545
if (ok != nullptr) *ok = false;
4646

4747
uint32_t length = 0;
48-
if (!this->readBytes(reinterpret_cast<char*>(&length), sizeof(length))) { // NOLINT
48+
if (!this->readBytes(reinterpret_cast<char*>(&length), sizeof(length))) {
4949
return "";
5050
}
5151

@@ -61,7 +61,7 @@ std::string PamIpcPipes::readString(bool* ok) const {
6161

6262
bool PamIpcPipes::writeString(const std::string& string) const {
6363
uint32_t length = string.length();
64-
if (!this->writeBytes(reinterpret_cast<char*>(&length), sizeof(length))) { // NOLINT
64+
if (!this->writeBytes(reinterpret_cast<char*>(&length), sizeof(length))) {
6565
return false;
6666
}
6767

0 commit comments

Comments
 (0)