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

Showing the changes to libavutil/intfloat_readwrite.c (1 of 1 file). Show all

Unified · Split

libavutil/intfloat_readwrite.c+2−2
@@ -30,13 +30,13 @@ · 29 unmodified lines
30#include "intfloat_readwrite.h"30#include "intfloat_readwrite.h"
31 31
32double av_int2dbl(int64_t v){32double av_int2dbl(int64_t v){
33 if(v+v > 0xFFEULL<<52)33 if((uint64_t)v+v > 0xFFEULL<<52)
34 return NAN;34 return NAN;
35 return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);35 return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
36}36}
37 37
38float av_int2flt(int32_t v){38float av_int2flt(int32_t v){
39 if(v+v > 0xFF000000U)39 if((uint32_t)v+v > 0xFF000000U)
40 return NAN;40 return NAN;
41 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);41 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
42}42}

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