[FFmpeg-devel,01/11] avformat/sdsdec: Fix undefined shifts

Submitted by Andreas Rheinhardt on Sept. 19, 2019, 10:16 p.m.

Details

Message ID 20190919221706.16529-2-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Sept. 19, 2019, 10:16 p.m.
An uint8_t gets promoted to an int before left shifting, so that it is
subject to the usual restrictions of signed types wrt shifts. Given that
the destination is an unsigned, simply convert to unsigned before
shifting.

Fixes tickets #8163, #8164 and #8165.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/sdsdec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/sdsdec.c b/libavformat/sdsdec.c
index 9c361cdff2..adc7d02a4d 100644
--- a/libavformat/sdsdec.c
+++ b/libavformat/sdsdec.c
@@ -43,7 +43,7 @@  static void byte2_read(const uint8_t *src, uint32_t *dst)
     int i;
 
     for (i = 0; i < 120; i += 2) {
-        unsigned sample = (src[i + 0] << 25) + (src[i + 1] << 18);
+        unsigned sample = ((unsigned)src[i + 0] << 25) + (src[i + 1] << 18);
 
         dst[i / 2] = sample;
     }
@@ -56,7 +56,7 @@  static void byte3_read(const uint8_t *src, uint32_t *dst)
     for (i = 0; i < 120; i += 3) {
         unsigned sample;
 
-        sample = (src[i + 0] << 25) | (src[i + 1] << 18) | (src[i + 2] << 11);
+        sample = ((unsigned)src[i + 0] << 25) | (src[i + 1] << 18) | (src[i + 2] << 11);
         dst[i / 3] = sample;
     }
 }
@@ -68,7 +68,7 @@  static void byte4_read(const uint8_t *src, uint32_t *dst)
     for (i = 0; i < 120; i += 4) {
         unsigned sample;
 
-        sample = (src[i + 0] << 25) | (src[i + 1] << 18) | (src[i + 2] << 11) | (src[i + 3] << 4);
+        sample = ((unsigned)src[i + 0] << 25) | (src[i + 1] << 18) | (src[i + 2] << 11) | (src[i + 3] << 4);
         dst[i / 4] = sample;
     }
 }