audioamplify: Fix integer overflows on 32 bit architectures

This commit is contained in:
Sebastian Dröge 2009-06-21 17:13:43 +02:00
parent f80b62c3db
commit a3cb8f005b

View File

@ -155,7 +155,7 @@ static GstFlowReturn gst_audio_amplify_transform_ip (GstBaseTransform * base,
#define MIN_gint32 G_MININT32 #define MIN_gint32 G_MININT32
#define MAX_gint32 G_MAXINT32 #define MAX_gint32 G_MAXINT32
#define MAKE_INT_FUNCS(type) \ #define MAKE_INT_FUNCS(type,largetype) \
static void \ static void \
gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \ gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
void * data, guint num_samples) \ void * data, guint num_samples) \
@ -163,7 +163,7 @@ gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
type *d = data; \ type *d = data; \
\ \
while (num_samples--) { \ while (num_samples--) { \
glong val = *d * filter->amplification; \ largetype val = *d * filter->amplification; \
*d++ = CLAMP (val, MIN_##type, MAX_##type); \ *d++ = CLAMP (val, MIN_##type, MAX_##type); \
} \ } \
} \ } \
@ -174,12 +174,12 @@ gst_audio_amplify_transform_##type##_wrap_negative (GstAudioAmplify * filter, \
type *d = data; \ type *d = data; \
\ \
while (num_samples--) { \ while (num_samples--) { \
glong val = *d * filter->amplification; \ largetype val = *d * filter->amplification; \
if (val > MAX_##type) \ if (val > MAX_##type) \
val = MIN_##type + (val - MIN_##type) % ((glong) MAX_##type + 1 - \ val = MIN_##type + (val - MIN_##type) % ((largetype) MAX_##type + 1 - \
MIN_##type); \ MIN_##type); \
else if (val < MIN_##type) \ else if (val < MIN_##type) \
val = MAX_##type - (MAX_##type - val) % ((glong) MAX_##type + 1 - \ val = MAX_##type - (MAX_##type - val) % ((largetype) MAX_##type + 1 - \
MIN_##type); \ MIN_##type); \
*d++ = val; \ *d++ = val; \
} \ } \
@ -191,7 +191,7 @@ gst_audio_amplify_transform_##type##_wrap_positive (GstAudioAmplify * filter, \
type *d = data; \ type *d = data; \
\ \
while (num_samples--) { \ while (num_samples--) { \
glong val = *d * filter->amplification; \ largetype val = *d * filter->amplification; \
do { \ do { \
if (val > MAX_##type) \ if (val > MAX_##type) \
val = MAX_##type - (val - MAX_##type); \ val = MAX_##type - (val - MAX_##type); \
@ -274,9 +274,9 @@ gst_audio_amplify_transform_##type##_noclip (GstAudioAmplify * filter, \
} }
/* *INDENT-OFF* */ /* *INDENT-OFF* */
MAKE_INT_FUNCS (gint8) MAKE_INT_FUNCS (gint8,gint)
MAKE_INT_FUNCS (gint16) MAKE_INT_FUNCS (gint16,gint)
MAKE_INT_FUNCS (gint32) MAKE_INT_FUNCS (gint32,gint64)
MAKE_FLOAT_FUNCS (gfloat) MAKE_FLOAT_FUNCS (gfloat)
MAKE_FLOAT_FUNCS (gdouble) MAKE_FLOAT_FUNCS (gdouble)
/* *INDENT-ON* */ /* *INDENT-ON* */