mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
compat: helper for detecting unsigned overflow
The idiom (a + b < a) works fine for detecting that an unsigned integer has overflowed, but a more explicit unsigned_add_overflows(a, b) might be easier to read. Define such a macro, expanding roughly to ((a) < UINT_MAX - (b)). Because the expansion uses each argument only once outside of sizeof() expressions, it is safe to use with arguments that have side effects. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
a8e4a5943a
commit
1368f65002
@@ -48,7 +48,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
|
||||
if (cmd & 0x20) cp_size |= (*data++ << 8);
|
||||
if (cmd & 0x40) cp_size |= (*data++ << 16);
|
||||
if (cp_size == 0) cp_size = 0x10000;
|
||||
if (cp_off + cp_size < cp_size ||
|
||||
if (unsigned_add_overflows(cp_off, cp_size) ||
|
||||
cp_off + cp_size > src_size ||
|
||||
cp_size > size)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user