diff options
author | Jøger Hansegård <joger.hansegard@qt.io> | 2023-05-30 13:03:34 +0200 |
---|---|---|
committer | Jøger Hansegård <joger.hansegard@qt.io> | 2023-06-01 15:23:56 +0000 |
commit | dda06373eba84999a89e539035860fc45f2fa5f5 (patch) | |
tree | 2ce1b9e740d0bfff0b16f8cd959885b6a5fa90a8 /src/multimedia/audio | |
parent | 8b9a271ddd6c1b0621d2f4f8577bcc1db205dd79 (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.
Pick-to: 6.5
Change-Id: Ifcc2db06310c94a7b90514f54d4d9e9c94c63072
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r-- | src/multimedia/audio/qwavedecoder.cpp | 11 |
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; |