From 4e931d11585e1baeddeea9a753007d835f8a3334 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Wed, 17 Aug 2016 21:28:00 +0200 Subject: [PATCH 04/10] plugins: audio_alsa: Fix byte truncating in 16-bit data (#218): This fixes a bug introduced in 82305c72 which basically was about muting a "dereferencing type-punned pointer will break strict-aliasing rules" compiler warning. --- plugins/audio_alsa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/audio_alsa.c b/plugins/audio_alsa.c index 20022f3..ff0d8a9 100644 --- a/plugins/audio_alsa.c +++ b/plugins/audio_alsa.c @@ -436,11 +436,12 @@ var_reset: /* Reset variables */ for (i = 0; i < count; i++) { /* cs == current sample */ unsigned char cs, as, sl, sz, xz; - short stmp; + unsigned short stmp; if (bytes_per_sample == 2) { - stmp = buff[i * bytes_per_sample * alsa_hw.num_channels + - bytes_per_sample * alsa_hw.channel]; + int ix = i * bytes_per_sample * alsa_hw.num_channels + + bytes_per_sample * alsa_hw.channel; + memcpy(&stmp, &buff[ix], sizeof(stmp)); cs = stmp >> 8; cs ^= 0x80; } else { -- 2.5.5