diff --git a/.clang-tidy b/.clang-tidy index 18c5cf3..e26363b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,6 +17,7 @@ Checks: > -cppcoreguidelines-avoid-goto, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-pro-type-reinterpret-cast, google-global-names-in-headers, google-readability-casting, google-runtime-int, diff --git a/src/core/logging.cpp b/src/core/logging.cpp index e260038..57b63e1 100644 --- a/src/core/logging.cpp +++ b/src/core/logging.cpp @@ -485,23 +485,21 @@ void WriteBuffer::writeBytes(const char* data, qsizetype length) { this->buffer.append(data, length); } -void WriteBuffer::writeU8(quint8 data) { - this->writeBytes(reinterpret_cast(&data), 1); // NOLINT -} +void WriteBuffer::writeU8(quint8 data) { this->writeBytes(reinterpret_cast(&data), 1); } void WriteBuffer::writeU16(quint16 data) { data = qToLittleEndian(data); - this->writeBytes(reinterpret_cast(&data), 2); // NOLINT + this->writeBytes(reinterpret_cast(&data), 2); } void WriteBuffer::writeU32(quint32 data) { data = qToLittleEndian(data); - this->writeBytes(reinterpret_cast(&data), 4); // NOLINT + this->writeBytes(reinterpret_cast(&data), 4); } void WriteBuffer::writeU64(quint64 data) { data = qToLittleEndian(data); - this->writeBytes(reinterpret_cast(&data), 8); // NOLINT + this->writeBytes(reinterpret_cast(&data), 8); } void DeviceReader::setDevice(QIODevice* device) { this->device = device; } @@ -518,19 +516,19 @@ qsizetype DeviceReader::peekBytes(char* data, qsizetype length) { bool DeviceReader::skip(qsizetype length) { return this->device->skip(length) == length; } bool DeviceReader::readU8(quint8* data) { - return this->readBytes(reinterpret_cast(data), 1); // NOLINT + return this->readBytes(reinterpret_cast(data), 1); } bool DeviceReader::readU16(quint16* data) { - return this->readBytes(reinterpret_cast(data), 2); // NOLINT + return this->readBytes(reinterpret_cast(data), 2); } bool DeviceReader::readU32(quint32* data) { - return this->readBytes(reinterpret_cast(data), 4); // NOLINT + return this->readBytes(reinterpret_cast(data), 4); } bool DeviceReader::readU64(quint64* data) { - return this->readBytes(reinterpret_cast(data), 8); // NOLINT + return this->readBytes(reinterpret_cast(data), 8); } void EncodedLogWriter::setDevice(QIODevice* target) { this->buffer.setDevice(target); } @@ -712,18 +710,18 @@ void EncodedLogWriter::writeVarInt(quint32 n) { bool EncodedLogReader::readVarInt(quint32* slot) { auto bytes = std::array(); - auto readLength = this->reader.peekBytes(reinterpret_cast(bytes.data()), 7); // NOLINT + auto readLength = this->reader.peekBytes(reinterpret_cast(bytes.data()), 7); if (bytes[0] != 0xff && readLength >= 1) { - auto n = *reinterpret_cast(bytes.data()); // NOLINT + auto n = *reinterpret_cast(bytes.data()); if (!this->reader.skip(1)) return false; *slot = qFromLittleEndian(n); } else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) { - auto n = *reinterpret_cast(bytes.data() + 1); // NOLINT + auto n = *reinterpret_cast(bytes.data() + 1); if (!this->reader.skip(3)) return false; *slot = qFromLittleEndian(n); } else if (readLength == 7) { - auto n = *reinterpret_cast(bytes.data() + 3); // NOLINT + auto n = *reinterpret_cast(bytes.data() + 3); if (!this->reader.skip(7)) return false; *slot = qFromLittleEndian(n); } else return false; diff --git a/src/core/util.hpp b/src/core/util.hpp index 84da1ac..719c920 100644 --- a/src/core/util.hpp +++ b/src/core/util.hpp @@ -65,7 +65,7 @@ public: template DropEmitter(O* object, void (*signal)(O*)) : object(object) - , signal(*reinterpret_cast(signal)) {} // NOLINT + , signal(*reinterpret_cast(signal)) {} DropEmitter() = default; diff --git a/src/dbus/dbusmenu/dbusmenu.cpp b/src/dbus/dbusmenu/dbusmenu.cpp index e015064..653ec8c 100644 --- a/src/dbus/dbusmenu/dbusmenu.cpp +++ b/src/dbus/dbusmenu/dbusmenu.cpp @@ -105,11 +105,11 @@ QQmlListProperty DBusMenuItem::children() { } qsizetype DBusMenuItem::childrenCount(QQmlListProperty* property) { - return reinterpret_cast(property->object)->enabledChildren.count(); // NOLINT + return reinterpret_cast(property->object)->enabledChildren.count(); } QsMenuEntry* DBusMenuItem::childAt(QQmlListProperty* property, qsizetype index) { - auto* item = reinterpret_cast(property->object); // NOLINT + auto* item = reinterpret_cast(property->object); return item->menu->items.value(item->enabledChildren.at(index)); } diff --git a/src/dbus/properties.cpp b/src/dbus/properties.cpp index 94a109c..a9ef2d2 100644 --- a/src/dbus/properties.cpp +++ b/src/dbus/properties.cpp @@ -37,7 +37,7 @@ QDBusError demarshallVariant(const QVariant& variant, const QMetaType& type, voi if (variant.metaType() == type) { if (type.id() == QMetaType::QVariant) { - *reinterpret_cast(slot) = variant; // NOLINT + *reinterpret_cast(slot) = variant; } else { type.destruct(slot); type.construct(slot, variant.constData()); diff --git a/src/io/fileview.cpp b/src/io/fileview.cpp index 924d55b..29e6971 100644 --- a/src/io/fileview.cpp +++ b/src/io/fileview.cpp @@ -281,7 +281,7 @@ void FileViewWriter::write( if (shouldCancel.loadAcquire()) return; if (doAtomicWrite) { - if (!reinterpret_cast(file.get())->commit()) { // NOLINT + if (!reinterpret_cast(file.get())->commit()) { qmlWarning(view) << "Write of " << state.path << " failed: Atomic commit failed."; } } diff --git a/src/services/greetd/connection.cpp b/src/services/greetd/connection.cpp index 4b59d79..822df5f 100644 --- a/src/services/greetd/connection.cpp +++ b/src/services/greetd/connection.cpp @@ -159,10 +159,7 @@ void GreetdConnection::onSocketError(QLocalSocket::LocalSocketError error) { void GreetdConnection::onSocketReady() { qint32 length = 0; - this->socket.read( - reinterpret_cast(&length), // NOLINT - sizeof(qint32) - ); + this->socket.read(reinterpret_cast(&length), sizeof(qint32)); auto text = this->socket.read(length); auto json = QJsonDocument::fromJson(text).object(); @@ -248,10 +245,7 @@ void GreetdConnection::sendRequest(const QJsonObject& json) { << QJsonDocument(debugJson).toJson(QJsonDocument::Compact); } - this->socket.write( - reinterpret_cast(&length), // NOLINT - sizeof(qint32) - ); + this->socket.write(reinterpret_cast(&length), sizeof(qint32)); this->socket.write(text); this->socket.flush(); diff --git a/src/services/notifications/dbusimage.cpp b/src/services/notifications/dbusimage.cpp index b292f02..46a72a7 100644 --- a/src/services/notifications/dbusimage.cpp +++ b/src/services/notifications/dbusimage.cpp @@ -15,7 +15,7 @@ QImage DBusNotificationImage::createImage() const { auto format = this->hasAlpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888; return QImage( - reinterpret_cast(this->data.data()), // NOLINT + reinterpret_cast(this->data.data()), this->width, this->height, format diff --git a/src/services/pam/conversation.cpp b/src/services/pam/conversation.cpp index c58f4fe..07dbd59 100644 --- a/src/services/pam/conversation.cpp +++ b/src/services/pam/conversation.cpp @@ -79,20 +79,14 @@ void PamConversation::onMessage() { auto type = PamIpcEvent::Exit; - auto ok = this->pipes.readBytes( - reinterpret_cast(&type), // NOLINT - sizeof(PamIpcEvent) - ); + auto ok = this->pipes.readBytes(reinterpret_cast(&type), sizeof(PamIpcEvent)); if (!ok) goto fail; if (type == PamIpcEvent::Exit) { auto code = PamIpcExitCode::OtherError; - ok = this->pipes.readBytes( - reinterpret_cast(&code), // NOLINT - sizeof(PamIpcExitCode) - ); + ok = this->pipes.readBytes(reinterpret_cast(&code), sizeof(PamIpcExitCode)); if (!ok) goto fail; @@ -112,10 +106,7 @@ void PamConversation::onMessage() { } else if (type == PamIpcEvent::Request) { PamIpcRequestFlags flags {}; - ok = this->pipes.readBytes( - reinterpret_cast(&flags), // NOLINT - sizeof(PamIpcRequestFlags) - ); + ok = this->pipes.readBytes(reinterpret_cast(&flags), sizeof(PamIpcRequestFlags)); if (!ok) goto fail; diff --git a/src/services/pam/ipc.cpp b/src/services/pam/ipc.cpp index 2b0e00b..0ac4d58 100644 --- a/src/services/pam/ipc.cpp +++ b/src/services/pam/ipc.cpp @@ -45,7 +45,7 @@ std::string PamIpcPipes::readString(bool* ok) const { if (ok != nullptr) *ok = false; uint32_t length = 0; - if (!this->readBytes(reinterpret_cast(&length), sizeof(length))) { // NOLINT + if (!this->readBytes(reinterpret_cast(&length), sizeof(length))) { return ""; } @@ -61,7 +61,7 @@ std::string PamIpcPipes::readString(bool* ok) const { bool PamIpcPipes::writeString(const std::string& string) const { uint32_t length = string.length(); - if (!this->writeBytes(reinterpret_cast(&length), sizeof(length))) { // NOLINT + if (!this->writeBytes(reinterpret_cast(&length), sizeof(length))) { return false; } diff --git a/src/services/pam/subprocess.cpp b/src/services/pam/subprocess.cpp index 276e8b9..f99b279 100644 --- a/src/services/pam/subprocess.cpp +++ b/src/services/pam/subprocess.cpp @@ -126,17 +126,11 @@ PamIpcExitCode PamSubprocess::exec(const char* configDir, const char* config, co void PamSubprocess::sendCode(PamIpcExitCode code) { { auto eventType = PamIpcEvent::Exit; - auto ok = this->pipes.writeBytes( - reinterpret_cast(&eventType), // NOLINT - sizeof(PamIpcEvent) - ); + auto ok = this->pipes.writeBytes(reinterpret_cast(&eventType), sizeof(PamIpcEvent)); if (!ok) goto fail; - ok = this->pipes.writeBytes( - reinterpret_cast(&code), // NOLINT - sizeof(PamIpcExitCode) - ); + ok = this->pipes.writeBytes(reinterpret_cast(&code), sizeof(PamIpcExitCode)); if (!ok) goto fail; @@ -175,17 +169,12 @@ int PamSubprocess::conversation( << std::endl; auto eventType = PamIpcEvent::Request; - auto ok = delegate->pipes.writeBytes( - reinterpret_cast(&eventType), // NOLINT - sizeof(PamIpcEvent) - ); + auto ok = delegate->pipes.writeBytes(reinterpret_cast(&eventType), sizeof(PamIpcEvent)); if (!ok) goto fail; - ok = delegate->pipes.writeBytes( - reinterpret_cast(&req), // NOLINT - sizeof(PamIpcRequestFlags) - ); + ok = + delegate->pipes.writeBytes(reinterpret_cast(&req), sizeof(PamIpcRequestFlags)); if (!ok) goto fail; if (!delegate->pipes.writeString(msgString)) goto fail; diff --git a/src/services/pipewire/core.hpp b/src/services/pipewire/core.hpp index bf7bd78..49728ee 100644 --- a/src/services/pipewire/core.hpp +++ b/src/services/pipewire/core.hpp @@ -42,9 +42,7 @@ template class PwObject { public: explicit PwObject(T* object = nullptr): object(object) {} - ~PwObject() { - pw_proxy_destroy(reinterpret_cast(this->object)); // NOLINT - } + ~PwObject() { pw_proxy_destroy(reinterpret_cast(this->object)); } Q_DISABLE_COPY_MOVE(PwObject); diff --git a/src/services/pipewire/node.cpp b/src/services/pipewire/node.cpp index 5eb38e7..b89bbff 100644 --- a/src/services/pipewire/node.cpp +++ b/src/services/pipewire/node.cpp @@ -459,19 +459,19 @@ PwVolumeProps PwVolumeProps::parseSpaPod(const spa_pod* param) { const auto* channelsProp = spa_pod_find_prop(param, nullptr, SPA_PROP_channelMap); const auto* muteProp = spa_pod_find_prop(param, nullptr, SPA_PROP_mute); - const auto* volumes = reinterpret_cast(&volumesProp->value); // NOLINT - const auto* channels = reinterpret_cast(&channelsProp->value); // NOLINT + const auto* volumes = reinterpret_cast(&volumesProp->value); + const auto* channels = reinterpret_cast(&channelsProp->value); spa_pod* iter = nullptr; SPA_POD_ARRAY_FOREACH(volumes, iter) { // Cubing behavior found in MPD source, and appears to corrospond to everyone else's measurements correctly. - auto linear = *reinterpret_cast(iter); // NOLINT + auto linear = *reinterpret_cast(iter); auto visual = std::cbrt(linear); props.volumes.push_back(visual); } SPA_POD_ARRAY_FOREACH(channels, iter) { - props.channels.push_back(*reinterpret_cast(iter)); // NOLINT + props.channels.push_back(*reinterpret_cast(iter)); } spa_pod_get_bool(&muteProp->value, &props.mute); diff --git a/src/services/pipewire/registry.hpp b/src/services/pipewire/registry.hpp index 59aac75..be282a2 100644 --- a/src/services/pipewire/registry.hpp +++ b/src/services/pipewire/registry.hpp @@ -67,9 +67,7 @@ QDebug operator<<(QDebug debug, const PwBindableObject* object); template class PwBindable: public PwBindableObject { public: - T* proxy() { - return reinterpret_cast(this->object); // NOLINT - } + T* proxy() { return reinterpret_cast(this->object); } protected: void bind() override { diff --git a/src/services/status_notifier/dbus_item_types.cpp b/src/services/status_notifier/dbus_item_types.cpp index 52f7fea..c751ca2 100644 --- a/src/services/status_notifier/dbus_item_types.cpp +++ b/src/services/status_notifier/dbus_item_types.cpp @@ -23,23 +23,23 @@ QImage DBusSniIconPixmap::createImage() const { // fix byte order if on a little endian machine if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { auto* newbuf = new quint32[this->data.size()]; - const auto* oldbuf = reinterpret_cast(this->data.constData()); // NOLINT + const auto* oldbuf = reinterpret_cast(this->data.constData()); for (uint i = 0; i < this->data.size() / sizeof(quint32); ++i) { newbuf[i] = qFromBigEndian(oldbuf[i]); // NOLINT } return QImage( - reinterpret_cast(newbuf), // NOLINT + reinterpret_cast(newbuf), this->width, this->height, QImage::Format_ARGB32, - [](void* ptr) { delete[] reinterpret_cast(ptr); }, // NOLINT + [](void* ptr) { delete[] reinterpret_cast(ptr); }, newbuf ); } else { return QImage( - reinterpret_cast(this->data.constData()), // NOLINT + reinterpret_cast(this->data.constData()), this->width, this->height, QImage::Format_ARGB32