Browse Source

mathops: remove undefined behaviour from sign_extend()

This function intentionally overflows the signed range on
the left shift.  Using this type-punning avoids errors from
the overflow checker without disabling this test globally.

Signed-off-by: Mans Rullgard <mans@mansr.com>
tags/n0.9
Mans Rullgard 14 years ago
parent
commit
f59bb3d8f3
1 changed files with 3 additions and 1 deletions
  1. +3
    -1
      libavcodec/mathops.h

+ 3
- 1
libavcodec/mathops.h View File

@@ -116,7 +116,9 @@ static inline av_const int mid_pred(int a, int b, int c)
#ifndef sign_extend
static inline av_const int sign_extend(int val, unsigned bits)
{
return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
unsigned shift = 8 * sizeof(int) - bits;
union { unsigned u; int s; } v = { (unsigned) val << shift };
return v.s >> shift;
}
#endif



Loading…
Cancel
Save