# SDL\_mixer: wav: Fix undefined behavior of shifting left on a negative number.

**URL:** <https://discourse.libsdl.org/t/sdl-mixer-wav-fix-undefined-behavior-of-shifting-left-on-a-negative-number/69756>\
**Category:** SDL Commits\
**Created:** [November 4, 2026, 9:03pm UTC](https://discourse.libsdl.org/t/sdl-mixer-wav-fix-undefined-behavior-of-shifting-left-on-a-negative-number/69756 "2026-11-04T21:03:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [November 4, 2026, 9:03pm UTC](https://discourse.libsdl.org/t/sdl-mixer-wav-fix-undefined-behavior-of-shifting-left-on-a-negative-number/69756/1 "2026-11-04T21:03:28Z")

</div>

> <https://github.com/libsdl-org/SDL_mixer/commit/7c74fd95a03316d6d9e3fc94c5b9b712fd1db6e3>
>
> Fixes #908.

```diff
From 7c74fd95a03316d6d9e3fc94c5b9b712fd1db6e3 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 4 Nov 2026 15:59:06 -0500
Subject: [PATCH] wav: Fix undefined behavior of shifting left on a negative
 number.

Fixes #908.
---
 src/decoder_wav.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/decoder_wav.c b/src/decoder_wav.c
index 0e86b611..457d8f76 100644
--- a/src/decoder_wav.c
+++ b/src/decoder_wav.c
@@ -786,7 +786,7 @@ static int FetchPCM24LE(WAV_TrackData *tdata, Uint8 *buffer, int buflen)
     int i = 0, o = 0;
     for (i = length - 3, o = ((length - 3) / 3) * 4; i >= 0; i -= 3, o -= 4) {
         const Uint8 *x = &buffer[i];
- const Sint32 in = ((Sint32)(Sint8)x[2] << 16) | ((int32_t)x[1] << 8) | x[0];
+ const Sint32 in = (((Sint32)(Sint8)x[2] * 65536) | ((Sint32)x[1] << 8) | x[0]); // `* 65536` because apparently `<< 16` on a negative number is undefined behavior. Whatever.
         float *out = (float *) &buffer[o];
         *out = ((float) in) / 8388608.0f;
     }

```
