History

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.

Mans Rullgard committed 15 years ago

Commit 88d1e2b1 parent 30c3d971 file · +2 −2Browse files

Unified · Split

libavutil/intfloat_readwrite.c+2−2
@@ -30,13 +30,13 @@ · 29 unmodified lines
3030 #include "intfloat_readwrite.h"
3131
3232 double av_int2dbl(int64_t v){
33− if(v+v > 0xFFEULL<<52)
33+ if((uint64_t)v+v > 0xFFEULL<<52)
3434 return NAN;
3535 return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
3636 }
3737
3838 float av_int2flt(int32_t v){
39− if(v+v > 0xFF000000U)
39+ if((uint32_t)v+v > 0xFF000000U)
4040 return NAN;
4141 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
4242 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t