summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2023-05-30 13:03:34 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-06-01 15:53:01 +0000
commitaed12bfee98a6d6483f9e754e800bdf02dd4e034 (patch)
tree0dc69557dbcb532e98bd5108b6ba4469ff79b2d8
parent87dbb54653611da2fc353f014c607727628a6409 (diff)
Multimedia: Fix compiler warning warning C4723: potential divide by 0
cl.exe 19.35.32217.1 for x64 emits warning C4723: potential divide by 0 in RelWithDebInfo build of QtMultimedia.dll. The reason is likely that the compiler can not rule out that the QAudioFormat::bytesPerSample returns a different value from the point of check to the point of read. Change-Id: Ifcc2db06310c94a7b90514f54d4d9e9c94c63072 Reviewed-by: Lars Knoll <lars@knoll.priv.no> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> (cherry picked from commit dda06373eba84999a89e539035860fc45f2fa5f5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/multimedia/audio/qwavedecoder.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/multimedia/audio/qwavedecoder.cpp b/src/multimedia/audio/qwavedecoder.cpp
index a61d49b06..df5ee32cc 100644
--- a/src/multimedia/audio/qwavedecoder.cpp
+++ b/src/multimedia/audio/qwavedecoder.cpp
@@ -139,7 +139,8 @@ qint64 QWaveDecoder::headerLength()
qint64 QWaveDecoder::readData(char *data, qint64 maxlen)
{
- if (!haveFormat || format.bytesPerSample() == 0)
+ const int bytesPerSample = format.bytesPerSample();
+ if (!haveFormat || bytesPerSample == 0)
return 0;
if (bps == 24) {
@@ -163,15 +164,15 @@ qint64 QWaveDecoder::readData(char *data, qint64 maxlen)
return l;
}
- qint64 nSamples = maxlen / format.bytesPerSample();
- maxlen = nSamples * format.bytesPerSample();
+ qint64 nSamples = maxlen / bytesPerSample;
+ maxlen = nSamples * bytesPerSample;
int read = device->read(data, maxlen);
if (!byteSwap || format.bytesPerFrame() == 1)
return read;
- nSamples = read / format.bytesPerSample();
- switch (format.bytesPerSample()) {
+ nSamples = read / bytesPerSample;
+ switch (bytesPerSample) {
case 2:
bswap2(data, nSamples);
break;