author | Jonathan Nieder <jrnieder@gmail.com> | |
Mon, 11 Oct 2010 02:59:26 +0000 (21:59 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 10 Feb 2011 21:47:56 +0000 (13:47 -0800) | ||
commit | 1368f65002bf39fdde7dd736a75ae35475184371 | |
tree | cb0d57165c5b1f710bb5e6499fa322185a8deb2f | tree | snapshot |
parent | a8e4a5943a63c8fd4a3a9b70ccf4608bcc973707 | commit | diff |
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>
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>
git-compat-util.h | diff | blob | history | |
patch-delta.c | diff | blob | history | |
strbuf.c | diff | blob | history | |
wrapper.c | diff | blob | history |