Skip to contentSkip to conversation

audio: fix integer overflow expression

PATCH In review Peter Maydell 3 participants 3 messages May 31, 2011

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 audio: fix integer overflow expression

From: Juha Riihimäki <[email protected]>

Fix an integer overflow that can happen for signed 32 bit types when using FLOAT_MIXENG. (Note that at the moment this is only true when using the MacOSX coreaudio audio driver.)

[Peter Maydell: Removed unnecessary casts]

---
v1->v2 : as suggested by Malc, removed one unnecessary cast from each change.

 audio/mixeng_template.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
audio/mixeng_template.h +2 -2
index a2d0ef8..a38055c 100644
@@ -46,7 +46,7 @@ static mixeng_real inline glue (conv_, ET) (IN_T v)
 #endif
 #else  /* !RECIPROCAL */
 #ifdef SIGNED
-    return nv / (mixeng_real) (IN_MAX - IN_MIN);
+    return nv / (mixeng_real) ((mixeng_real)IN_MAX - IN_MIN);
 #else
     return (nv - HALF) / (mixeng_real) IN_MAX;
 #endif
@@ -63,7 +63,7 @@ static IN_T inline glue (clip_, ET) (mixeng_real v)
     }
 
 #ifdef SIGNED
-    return ENDIAN_CONVERT ((IN_T) (v * (IN_MAX - IN_MIN)));
+    return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real)IN_MAX - IN_MIN)));
 #else
     return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
 #endif
Signature · 1 line
1.7.1
Tested-by on v2 1/1
#1 lore raw

Am 31.05.2011 um 20:40 schrieb Peter Maydell:

Quoted 9 lines

From: Juha Riihimäki <[email protected]>

Fix an integer overflow that can happen for signed 32 bit types when using FLOAT_MIXENG. (Note that at the moment this is only true when using the MacOSX coreaudio audio driver.)

[Peter Maydell: Removed unnecessary casts]

Silences the warnings for me.

Thanks,
Andreas

Quoted 33 lines

---
v1->v2 : as suggested by Malc, removed one unnecessary cast from each change.

audio/mixeng_template.h | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
audio/mixeng_template.h +2 -2
index a2d0ef8..a38055c 100644
@@ -46,7 +46,7 @@ static mixeng_real inline glue (conv_, ET) (IN_T v)
 #endif
 #else  /* !RECIPROCAL */
 #ifdef SIGNED
-    return nv / (mixeng_real) (IN_MAX - IN_MIN);
+    return nv / (mixeng_real) ((mixeng_real)IN_MAX - IN_MIN);
 #else
    return (nv - HALF) / (mixeng_real) IN_MAX;
 #endif
@@ -63,7 +63,7 @@ static IN_T inline glue (clip_, ET) (mixeng_real v)
    }
 
 #ifdef SIGNED
-    return ENDIAN_CONVERT ((IN_T) (v * (IN_MAX - IN_MIN)));
+    return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real)IN_MAX -  
 IN_MIN)));
 #else
    return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));

#endif

Signature · 1 line
1.7.1
#2 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell

From: Juha Riihim?ki <[email protected]>

Fix an integer overflow that can happen for signed 32 bit types when using FLOAT_MIXENG. (Note that at the moment this is only true when using the MacOSX coreaudio audio driver.)

Quoted 6 lines
[Peter Maydell: Removed unnecessary casts]

---
v1->v2 : as suggested by Malc, removed one unnecessary cast from each change.

Applied with minor stylistic change, thanks to all involved.

[..snip..]

Signature · 1 line
mailto:[email protected]