lint: remove reinterpret_cast lint

Unhelpful.
This commit is contained in:
outfoxxed 2024-12-06 20:07:51 -08:00
parent be5e5fc4a5
commit 3fc1c914c7
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
15 changed files with 41 additions and 72 deletions

View file

@ -17,6 +17,7 @@ Checks: >
-cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-goto,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-global-names-in-headers, google-global-names-in-headers,
google-readability-casting, google-readability-casting,
google-runtime-int, google-runtime-int,

View file

@ -485,23 +485,21 @@ void WriteBuffer::writeBytes(const char* data, qsizetype length) {
this->buffer.append(data, length); this->buffer.append(data, length);
} }
void WriteBuffer::writeU8(quint8 data) { void WriteBuffer::writeU8(quint8 data) { this->writeBytes(reinterpret_cast<char*>(&data), 1); }
this->writeBytes(reinterpret_cast<char*>(&data), 1); // NOLINT
}
void WriteBuffer::writeU16(quint16 data) { void WriteBuffer::writeU16(quint16 data) {
data = qToLittleEndian(data); data = qToLittleEndian(data);
this->writeBytes(reinterpret_cast<char*>(&data), 2); // NOLINT this->writeBytes(reinterpret_cast<char*>(&data), 2);
} }
void WriteBuffer::writeU32(quint32 data) { void WriteBuffer::writeU32(quint32 data) {
data = qToLittleEndian(data); data = qToLittleEndian(data);
this->writeBytes(reinterpret_cast<char*>(&data), 4); // NOLINT this->writeBytes(reinterpret_cast<char*>(&data), 4);
} }
void WriteBuffer::writeU64(quint64 data) { void WriteBuffer::writeU64(quint64 data) {
data = qToLittleEndian(data); data = qToLittleEndian(data);
this->writeBytes(reinterpret_cast<char*>(&data), 8); // NOLINT this->writeBytes(reinterpret_cast<char*>(&data), 8);
} }
void DeviceReader::setDevice(QIODevice* device) { this->device = device; } 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::skip(qsizetype length) { return this->device->skip(length) == length; }
bool DeviceReader::readU8(quint8* data) { bool DeviceReader::readU8(quint8* data) {
return this->readBytes(reinterpret_cast<char*>(data), 1); // NOLINT return this->readBytes(reinterpret_cast<char*>(data), 1);
} }
bool DeviceReader::readU16(quint16* data) { bool DeviceReader::readU16(quint16* data) {
return this->readBytes(reinterpret_cast<char*>(data), 2); // NOLINT return this->readBytes(reinterpret_cast<char*>(data), 2);
} }
bool DeviceReader::readU32(quint32* data) { bool DeviceReader::readU32(quint32* data) {
return this->readBytes(reinterpret_cast<char*>(data), 4); // NOLINT return this->readBytes(reinterpret_cast<char*>(data), 4);
} }
bool DeviceReader::readU64(quint64* data) { bool DeviceReader::readU64(quint64* data) {
return this->readBytes(reinterpret_cast<char*>(data), 8); // NOLINT return this->readBytes(reinterpret_cast<char*>(data), 8);
} }
void EncodedLogWriter::setDevice(QIODevice* target) { this->buffer.setDevice(target); } void EncodedLogWriter::setDevice(QIODevice* target) { this->buffer.setDevice(target); }
@ -712,18 +710,18 @@ void EncodedLogWriter::writeVarInt(quint32 n) {
bool EncodedLogReader::readVarInt(quint32* slot) { bool EncodedLogReader::readVarInt(quint32* slot) {
auto bytes = std::array<quint8, 7>(); auto bytes = std::array<quint8, 7>();
auto readLength = this->reader.peekBytes(reinterpret_cast<char*>(bytes.data()), 7); // NOLINT auto readLength = this->reader.peekBytes(reinterpret_cast<char*>(bytes.data()), 7);
if (bytes[0] != 0xff && readLength >= 1) { if (bytes[0] != 0xff && readLength >= 1) {
auto n = *reinterpret_cast<quint8*>(bytes.data()); // NOLINT auto n = *reinterpret_cast<quint8*>(bytes.data());
if (!this->reader.skip(1)) return false; if (!this->reader.skip(1)) return false;
*slot = qFromLittleEndian(n); *slot = qFromLittleEndian(n);
} else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) { } else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) {
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1); // NOLINT auto n = *reinterpret_cast<quint16*>(bytes.data() + 1);
if (!this->reader.skip(3)) return false; if (!this->reader.skip(3)) return false;
*slot = qFromLittleEndian(n); *slot = qFromLittleEndian(n);
} else if (readLength == 7) { } else if (readLength == 7) {
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3); // NOLINT auto n = *reinterpret_cast<quint32*>(bytes.data() + 3);
if (!this->reader.skip(7)) return false; if (!this->reader.skip(7)) return false;
*slot = qFromLittleEndian(n); *slot = qFromLittleEndian(n);
} else return false; } else return false;

View file

@ -65,7 +65,7 @@ public:
template <class O> template <class O>
DropEmitter(O* object, void (*signal)(O*)) DropEmitter(O* object, void (*signal)(O*))
: object(object) : object(object)
, signal(*reinterpret_cast<void (*)(void*)>(signal)) {} // NOLINT , signal(*reinterpret_cast<void (*)(void*)>(signal)) {}
DropEmitter() = default; DropEmitter() = default;

View file

@ -105,11 +105,11 @@ QQmlListProperty<QsMenuEntry> DBusMenuItem::children() {
} }
qsizetype DBusMenuItem::childrenCount(QQmlListProperty<QsMenuEntry>* property) { qsizetype DBusMenuItem::childrenCount(QQmlListProperty<QsMenuEntry>* property) {
return reinterpret_cast<DBusMenuItem*>(property->object)->enabledChildren.count(); // NOLINT return reinterpret_cast<DBusMenuItem*>(property->object)->enabledChildren.count();
} }
QsMenuEntry* DBusMenuItem::childAt(QQmlListProperty<QsMenuEntry>* property, qsizetype index) { QsMenuEntry* DBusMenuItem::childAt(QQmlListProperty<QsMenuEntry>* property, qsizetype index) {
auto* item = reinterpret_cast<DBusMenuItem*>(property->object); // NOLINT auto* item = reinterpret_cast<DBusMenuItem*>(property->object);
return item->menu->items.value(item->enabledChildren.at(index)); return item->menu->items.value(item->enabledChildren.at(index));
} }

View file

@ -37,7 +37,7 @@ QDBusError demarshallVariant(const QVariant& variant, const QMetaType& type, voi
if (variant.metaType() == type) { if (variant.metaType() == type) {
if (type.id() == QMetaType::QVariant) { if (type.id() == QMetaType::QVariant) {
*reinterpret_cast<QVariant*>(slot) = variant; // NOLINT *reinterpret_cast<QVariant*>(slot) = variant;
} else { } else {
type.destruct(slot); type.destruct(slot);
type.construct(slot, variant.constData()); type.construct(slot, variant.constData());

View file

@ -281,7 +281,7 @@ void FileViewWriter::write(
if (shouldCancel.loadAcquire()) return; if (shouldCancel.loadAcquire()) return;
if (doAtomicWrite) { if (doAtomicWrite) {
if (!reinterpret_cast<QSaveFile*>(file.get())->commit()) { // NOLINT if (!reinterpret_cast<QSaveFile*>(file.get())->commit()) {
qmlWarning(view) << "Write of " << state.path << " failed: Atomic commit failed."; qmlWarning(view) << "Write of " << state.path << " failed: Atomic commit failed.";
} }
} }

View file

@ -159,10 +159,7 @@ void GreetdConnection::onSocketError(QLocalSocket::LocalSocketError error) {
void GreetdConnection::onSocketReady() { void GreetdConnection::onSocketReady() {
qint32 length = 0; qint32 length = 0;
this->socket.read( this->socket.read(reinterpret_cast<char*>(&length), sizeof(qint32));
reinterpret_cast<char*>(&length), // NOLINT
sizeof(qint32)
);
auto text = this->socket.read(length); auto text = this->socket.read(length);
auto json = QJsonDocument::fromJson(text).object(); auto json = QJsonDocument::fromJson(text).object();
@ -248,10 +245,7 @@ void GreetdConnection::sendRequest(const QJsonObject& json) {
<< QJsonDocument(debugJson).toJson(QJsonDocument::Compact); << QJsonDocument(debugJson).toJson(QJsonDocument::Compact);
} }
this->socket.write( this->socket.write(reinterpret_cast<char*>(&length), sizeof(qint32));
reinterpret_cast<char*>(&length), // NOLINT
sizeof(qint32)
);
this->socket.write(text); this->socket.write(text);
this->socket.flush(); this->socket.flush();

View file

@ -15,7 +15,7 @@ QImage DBusNotificationImage::createImage() const {
auto format = this->hasAlpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888; auto format = this->hasAlpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888;
return QImage( return QImage(
reinterpret_cast<const uchar*>(this->data.data()), // NOLINT reinterpret_cast<const uchar*>(this->data.data()),
this->width, this->width,
this->height, this->height,
format format

View file

@ -79,20 +79,14 @@ void PamConversation::onMessage() {
auto type = PamIpcEvent::Exit; auto type = PamIpcEvent::Exit;
auto ok = this->pipes.readBytes( auto ok = this->pipes.readBytes(reinterpret_cast<char*>(&type), sizeof(PamIpcEvent));
reinterpret_cast<char*>(&type), // NOLINT
sizeof(PamIpcEvent)
);
if (!ok) goto fail; if (!ok) goto fail;
if (type == PamIpcEvent::Exit) { if (type == PamIpcEvent::Exit) {
auto code = PamIpcExitCode::OtherError; auto code = PamIpcExitCode::OtherError;
ok = this->pipes.readBytes( ok = this->pipes.readBytes(reinterpret_cast<char*>(&code), sizeof(PamIpcExitCode));
reinterpret_cast<char*>(&code), // NOLINT
sizeof(PamIpcExitCode)
);
if (!ok) goto fail; if (!ok) goto fail;
@ -112,10 +106,7 @@ void PamConversation::onMessage() {
} else if (type == PamIpcEvent::Request) { } else if (type == PamIpcEvent::Request) {
PamIpcRequestFlags flags {}; PamIpcRequestFlags flags {};
ok = this->pipes.readBytes( ok = this->pipes.readBytes(reinterpret_cast<char*>(&flags), sizeof(PamIpcRequestFlags));
reinterpret_cast<char*>(&flags), // NOLINT
sizeof(PamIpcRequestFlags)
);
if (!ok) goto fail; if (!ok) goto fail;

View file

@ -45,7 +45,7 @@ std::string PamIpcPipes::readString(bool* ok) const {
if (ok != nullptr) *ok = false; if (ok != nullptr) *ok = false;
uint32_t length = 0; uint32_t length = 0;
if (!this->readBytes(reinterpret_cast<char*>(&length), sizeof(length))) { // NOLINT if (!this->readBytes(reinterpret_cast<char*>(&length), sizeof(length))) {
return ""; return "";
} }
@ -61,7 +61,7 @@ std::string PamIpcPipes::readString(bool* ok) const {
bool PamIpcPipes::writeString(const std::string& string) const { bool PamIpcPipes::writeString(const std::string& string) const {
uint32_t length = string.length(); uint32_t length = string.length();
if (!this->writeBytes(reinterpret_cast<char*>(&length), sizeof(length))) { // NOLINT if (!this->writeBytes(reinterpret_cast<char*>(&length), sizeof(length))) {
return false; return false;
} }

View file

@ -126,17 +126,11 @@ PamIpcExitCode PamSubprocess::exec(const char* configDir, const char* config, co
void PamSubprocess::sendCode(PamIpcExitCode code) { void PamSubprocess::sendCode(PamIpcExitCode code) {
{ {
auto eventType = PamIpcEvent::Exit; auto eventType = PamIpcEvent::Exit;
auto ok = this->pipes.writeBytes( auto ok = this->pipes.writeBytes(reinterpret_cast<char*>(&eventType), sizeof(PamIpcEvent));
reinterpret_cast<char*>(&eventType), // NOLINT
sizeof(PamIpcEvent)
);
if (!ok) goto fail; if (!ok) goto fail;
ok = this->pipes.writeBytes( ok = this->pipes.writeBytes(reinterpret_cast<char*>(&code), sizeof(PamIpcExitCode));
reinterpret_cast<char*>(&code), // NOLINT
sizeof(PamIpcExitCode)
);
if (!ok) goto fail; if (!ok) goto fail;
@ -175,17 +169,12 @@ int PamSubprocess::conversation(
<< std::endl; << std::endl;
auto eventType = PamIpcEvent::Request; auto eventType = PamIpcEvent::Request;
auto ok = delegate->pipes.writeBytes( auto ok = delegate->pipes.writeBytes(reinterpret_cast<char*>(&eventType), sizeof(PamIpcEvent));
reinterpret_cast<char*>(&eventType), // NOLINT
sizeof(PamIpcEvent)
);
if (!ok) goto fail; if (!ok) goto fail;
ok = delegate->pipes.writeBytes( ok =
reinterpret_cast<const char*>(&req), // NOLINT delegate->pipes.writeBytes(reinterpret_cast<const char*>(&req), sizeof(PamIpcRequestFlags));
sizeof(PamIpcRequestFlags)
);
if (!ok) goto fail; if (!ok) goto fail;
if (!delegate->pipes.writeString(msgString)) goto fail; if (!delegate->pipes.writeString(msgString)) goto fail;

View file

@ -42,9 +42,7 @@ template <typename T>
class PwObject { class PwObject {
public: public:
explicit PwObject(T* object = nullptr): object(object) {} explicit PwObject(T* object = nullptr): object(object) {}
~PwObject() { ~PwObject() { pw_proxy_destroy(reinterpret_cast<pw_proxy*>(this->object)); }
pw_proxy_destroy(reinterpret_cast<pw_proxy*>(this->object)); // NOLINT
}
Q_DISABLE_COPY_MOVE(PwObject); Q_DISABLE_COPY_MOVE(PwObject);

View file

@ -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* channelsProp = spa_pod_find_prop(param, nullptr, SPA_PROP_channelMap);
const auto* muteProp = spa_pod_find_prop(param, nullptr, SPA_PROP_mute); const auto* muteProp = spa_pod_find_prop(param, nullptr, SPA_PROP_mute);
const auto* volumes = reinterpret_cast<const spa_pod_array*>(&volumesProp->value); // NOLINT const auto* volumes = reinterpret_cast<const spa_pod_array*>(&volumesProp->value);
const auto* channels = reinterpret_cast<const spa_pod_array*>(&channelsProp->value); // NOLINT const auto* channels = reinterpret_cast<const spa_pod_array*>(&channelsProp->value);
spa_pod* iter = nullptr; spa_pod* iter = nullptr;
SPA_POD_ARRAY_FOREACH(volumes, iter) { SPA_POD_ARRAY_FOREACH(volumes, iter) {
// Cubing behavior found in MPD source, and appears to corrospond to everyone else's measurements correctly. // Cubing behavior found in MPD source, and appears to corrospond to everyone else's measurements correctly.
auto linear = *reinterpret_cast<float*>(iter); // NOLINT auto linear = *reinterpret_cast<float*>(iter);
auto visual = std::cbrt(linear); auto visual = std::cbrt(linear);
props.volumes.push_back(visual); props.volumes.push_back(visual);
} }
SPA_POD_ARRAY_FOREACH(channels, iter) { SPA_POD_ARRAY_FOREACH(channels, iter) {
props.channels.push_back(*reinterpret_cast<PwAudioChannel::Enum*>(iter)); // NOLINT props.channels.push_back(*reinterpret_cast<PwAudioChannel::Enum*>(iter));
} }
spa_pod_get_bool(&muteProp->value, &props.mute); spa_pod_get_bool(&muteProp->value, &props.mute);

View file

@ -67,9 +67,7 @@ QDebug operator<<(QDebug debug, const PwBindableObject* object);
template <typename T, StringLiteral INTERFACE, quint32 VERSION> template <typename T, StringLiteral INTERFACE, quint32 VERSION>
class PwBindable: public PwBindableObject { class PwBindable: public PwBindableObject {
public: public:
T* proxy() { T* proxy() { return reinterpret_cast<T*>(this->object); }
return reinterpret_cast<T*>(this->object); // NOLINT
}
protected: protected:
void bind() override { void bind() override {

View file

@ -23,23 +23,23 @@ QImage DBusSniIconPixmap::createImage() const {
// fix byte order if on a little endian machine // fix byte order if on a little endian machine
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
auto* newbuf = new quint32[this->data.size()]; auto* newbuf = new quint32[this->data.size()];
const auto* oldbuf = reinterpret_cast<const quint32*>(this->data.constData()); // NOLINT const auto* oldbuf = reinterpret_cast<const quint32*>(this->data.constData());
for (uint i = 0; i < this->data.size() / sizeof(quint32); ++i) { for (uint i = 0; i < this->data.size() / sizeof(quint32); ++i) {
newbuf[i] = qFromBigEndian(oldbuf[i]); // NOLINT newbuf[i] = qFromBigEndian(oldbuf[i]); // NOLINT
} }
return QImage( return QImage(
reinterpret_cast<const uchar*>(newbuf), // NOLINT reinterpret_cast<const uchar*>(newbuf),
this->width, this->width,
this->height, this->height,
QImage::Format_ARGB32, QImage::Format_ARGB32,
[](void* ptr) { delete[] reinterpret_cast<quint32*>(ptr); }, // NOLINT [](void* ptr) { delete[] reinterpret_cast<quint32*>(ptr); },
newbuf newbuf
); );
} else { } else {
return QImage( return QImage(
reinterpret_cast<const uchar*>(this->data.constData()), // NOLINT reinterpret_cast<const uchar*>(this->data.constData()),
this->width, this->width,
this->height, this->height,
QImage::Format_ARGB32 QImage::Format_ARGB32