Skip to content

Commit

Permalink
Don't cast byte arrays to char * implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolby committed Dec 4, 2023
1 parent 804b7cb commit 092811f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ add_definitions(
-DQT_NO_FOREACH
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
#-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
-DQT_NO_CONTEXTLESS_CONNECT
Expand Down
16 changes: 8 additions & 8 deletions src/lib/dataloggerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ DataLoggerService::Metadata DataLoggerServicePrivate::parseMetadata(const QByteA

qCDebug(lc) << value.mid(7,12).toHex(',');
metadata.status = static_cast<DataLoggerService::LoggerStatus>(value.at(0));
metadata.scale = qFromLittleEndian<float>(value.mid(1,4));
metadata.scale = qFromLittleEndian<float>(value.mid(1,4).constData());
metadata.mode = static_cast<DataLoggerService::Mode>(value.at(5));
metadata.range = static_cast<quint8>(value.at(6));

Expand All @@ -416,13 +416,13 @@ DataLoggerService::Metadata DataLoggerServicePrivate::parseMetadata(const QByteA
*/

if (value.size() == 15) {
metadata.updateInterval = qFromLittleEndian<quint16>(value.mid(7,2))*1000;
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(9,2));
metadata.timestamp = qFromLittleEndian<quint32>(value.mid(11,4));
metadata.updateInterval = qFromLittleEndian<quint16>(value.mid(7,2).constData())*1000;
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(9,2).constData());
metadata.timestamp = qFromLittleEndian<quint32>(value.mid(11,4).constData());
} else if (value.size() == 23) {
metadata.updateInterval = qFromLittleEndian<quint32>(value.mid(7,4));
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(11,2));
metadata.timestamp = qFromLittleEndian<quint32>(value.mid(19,4));
metadata.updateInterval = qFromLittleEndian<quint32>(value.mid(7,4).constData());
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(11,2).constData());
metadata.timestamp = qFromLittleEndian<quint32>(value.mid(19,4).constData());
} else {
qCWarning(lc).noquote() << tr("Cannot decode metadata of %n byte/s: %1", nullptr, value.size())
.arg(toHexString(value));
Expand All @@ -442,7 +442,7 @@ DataLoggerService::Samples DataLoggerServicePrivate::parseSamples(const QByteArr
return samples;
}
while ((samples.size()*2) < value.size()) {
samples.append(qFromLittleEndian<qint16>(value.mid(samples.size()*2,2)));
samples.append(qFromLittleEndian<qint16>(value.mid(samples.size()*2,2).constData()));
}
qCDebug(lc).noquote() << tr("Read %n sample/s from %1-bytes.", nullptr, samples.size()).arg(value.size());
return samples;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/dsoservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ DsoService::Metadata DsoServicePrivate::parseMetadata(const QByteArray &value)
}

metadata.status = static_cast<DsoService::DsoStatus>(value.at(0));
metadata.scale = qFromLittleEndian<float>(value.mid(1,4));
metadata.scale = qFromLittleEndian<float>(value.mid(1,4).constData());
metadata.mode = static_cast<DsoService::Mode>(value.at(5));
metadata.range = static_cast<quint8>(value.at(6));
metadata.samplingWindow = qFromLittleEndian<quint32>(value.mid(7,4));
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(11,2));
metadata.samplingRate = qFromLittleEndian<quint32>(value.mid(13,4));
metadata.samplingWindow = qFromLittleEndian<quint32>(value.mid(7,4).constData());
metadata.numberOfSamples = qFromLittleEndian<quint16>(value.mid(11,2).constData());
metadata.samplingRate = qFromLittleEndian<quint32>(value.mid(13,4).constData());
return metadata;
}

Expand All @@ -387,7 +387,7 @@ DsoService::Samples DsoServicePrivate::parseSamples(const QByteArray &value)
return samples;
}
while ((samples.size()*2) < value.size()) {
samples.append(qFromLittleEndian<qint16>(value.mid(samples.size()*2,2)));
samples.append(qFromLittleEndian<qint16>(value.mid(samples.size()*2,2).constData()));
}
qCDebug(lc).noquote() << tr("Read %n sample/s from %1-bytes.", nullptr, samples.size()).arg(value.size());
return samples;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/genericaccessservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ quint16 GenericAccessServicePrivate::parseAppearance(const QByteArray &value)
if (!checkSize(QLatin1String("Appearance"), value, 2, 2)) {
return std::numeric_limits<quint16>::max();
}
const quint16 appearance = qFromLittleEndian<quint16>(value);
const quint16 appearance = qFromLittleEndian<quint16>(value.constData());
qCDebug(lc).noquote() << tr("Appearance: %1.").arg(appearance);
return appearance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/multimeterservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ MultimeterService::Reading MultimeterServicePrivate::parseReading(const QByteArr
}

reading.status = MultimeterService::MeterStatus(value.at(0));
reading.value = qFromLittleEndian<float>(value.mid(1,4));
reading.value = qFromLittleEndian<float>(value.mid(1,4).constData());
reading.mode = static_cast<MultimeterService::Mode>(value.at(5));
reading.range = static_cast<quint8>(value.at(6));
return reading;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/statusservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,16 @@ StatusService::DeviceCharacteristics StatusServicePrivate::parseDeviceCharacteri
}

characteristics.firmwareVersion = QVersionNumber(
qFromLittleEndian<quint8 >(value.mid(0,1)),
qFromLittleEndian<quint8 >(value.mid(1,1)));
characteristics.maximumVoltage = qFromLittleEndian<quint16>(value.mid(2,2));
characteristics.maximumCurrent = qFromLittleEndian<quint16>(value.mid(4,2));
characteristics.maximumResistance = qFromLittleEndian<quint16>(value.mid(6,2));
characteristics.maximumSamplingRate = qFromLittleEndian<quint16>(value.mid(8,2));
characteristics.samplingBufferSize = qFromLittleEndian<quint16>(value.mid(10,2));
characteristics.capabilityMask = qFromLittleEndian<quint16>(value.mid(12,2));
qFromLittleEndian<quint8 >(value.mid(0,1).constData()),
qFromLittleEndian<quint8 >(value.mid(1,1).constData()));
characteristics.maximumVoltage = qFromLittleEndian<quint16>(value.mid(2,2).constData());
characteristics.maximumCurrent = qFromLittleEndian<quint16>(value.mid(4,2).constData());
characteristics.maximumResistance = qFromLittleEndian<quint16>(value.mid(6,2).constData());
characteristics.maximumSamplingRate = qFromLittleEndian<quint16>(value.mid(8,2).constData());
characteristics.samplingBufferSize = qFromLittleEndian<quint16>(value.mid(10,2).constData());
characteristics.capabilityMask = qFromLittleEndian<quint16>(value.mid(12,2).constData());
characteristics.macAddress = QBluetoothAddress(qFromBigEndian<quint64>
(QByteArray(2, '\0') + value.mid(14,6)));
((QByteArray(2, '\0') + value.mid(14,6)).constData()));

qCDebug(lc).noquote() << tr("Firmware version: ") << characteristics.firmwareVersion;
qCDebug(lc).noquote() << tr("Maximum voltage: ") << characteristics.maximumVoltage;
Expand Down Expand Up @@ -646,7 +646,7 @@ StatusService::Status StatusServicePrivate::parseStatus(const QByteArray &value)
}

status.deviceStatus = static_cast<StatusService::DeviceStatus>(value.at(0));
status.batteryVoltage = qFromLittleEndian<float>(value.mid(1,4));
status.batteryVoltage = qFromLittleEndian<float>(value.mid(1,4).constData());
if (value.size() >= 6) { // Battery Status added to Pokit API docs v1.00.
status.batteryStatus = static_cast<StatusService::BatteryStatus>(value.at(5));
}
Expand Down

0 comments on commit 092811f

Please sign in to comment.