summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2011-10-08 02:16:29 +0100
committerMans Rullgard <mans@mansr.com>2011-10-11 14:42:28 +0100
commit88d1e2b2b0a129365a62efd666db0394e8ffbe08 (patch)
tree8e4e3332f3d7d863325e4e0412a32d0a633dcb8e /libavutil
parent30c3d976f12665d5d13971172aab062a97cb1bce (diff)
intfloat_readwrite: fix signed addition overflows
These additions might overflow the signed range for large input values. Converting to unsigned before the addition rather than after avoids such undefined behaviour. The result under normal two's complement wraparound remains unchanged. Signed-off-by: Mans Rullgard <mans@mansr.com>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/intfloat_readwrite.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c
index 21a1c31667..4c8de7b7a8 100644
--- a/libavutil/intfloat_readwrite.c
+++ b/libavutil/intfloat_readwrite.c
@@ -30,13 +30,13 @@
#include "intfloat_readwrite.h"
double av_int2dbl(int64_t v){
- if(v+v > 0xFFEULL<<52)
+ if((uint64_t)v+v > 0xFFEULL<<52)
return NAN;
return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
}
float av_int2flt(int32_t v){
- if(v+v > 0xFF000000U)
+ if((uint32_t)v+v > 0xFF000000U)
return NAN;
return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
}