diff options
| author | Antonin Descampe <antonin@gmail.com> | 2015-02-02 16:11:31 +0000 |
|---|---|---|
| committer | Antonin Descampe <antonin@gmail.com> | 2015-02-02 16:11:31 +0000 |
| commit | 2d24b6000d5611615e3e6d799e20d5fdbe4e2a1e (patch) | |
| tree | cb6e97e4d5614245020e0b373a82fc827e7095a3 /src/lib/openjp2/opj_intmath.h | |
| parent | 8b5e2a51430245c06185f46c796670d9c17ff4e9 (diff) | |
[trunk] added overflow checks (fixes issue 431)
Thanks mdarbois
Diffstat (limited to 'src/lib/openjp2/opj_intmath.h')
| -rw-r--r-- | src/lib/openjp2/opj_intmath.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/openjp2/opj_intmath.h b/src/lib/openjp2/opj_intmath.h index 641fcaa2..4e299469 100644 --- a/src/lib/openjp2/opj_intmath.h +++ b/src/lib/openjp2/opj_intmath.h @@ -82,6 +82,15 @@ static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { } /** + Get the saturated sum of two unsigned integers + @return Returns saturated sum of a+b + */ +static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { + OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; + return -(OPJ_UINT32)(sum >> 32) | (OPJ_UINT32)sum; +} + +/** Clamp an integer inside an interval @return <ul> |
