diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-02-10 14:45:55 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-02-10 14:45:55 -0800 |
commit | b308bf18633964102472db5065929a359d4ad265 (patch) | |
tree | ad03f24d6bcaa3228f20f0141e73bdadffaf3cda /git-compat-util.h | |
parent | 1a9fe453263137be7d42e6fbfc041b5b2d9521d7 (diff) | |
parent | 1368f65002bf39fdde7dd736a75ae35475184371 (diff) | |
download | git-b308bf18633964102472db5065929a359d4ad265.tar.gz git-b308bf18633964102472db5065929a359d4ad265.tar.xz |
Merge branch 'maint'
* maint:
compat: helper for detecting unsigned overflow
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index d6d269f13..9c23622ed 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -31,6 +31,9 @@ #define maximum_signed_value_of_type(a) \ (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) +#define maximum_unsigned_value_of_type(a) \ + (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) + /* * Signed integer overflow is undefined in C, so here's a helper macro * to detect if the sum of two integers will overflow. @@ -40,6 +43,9 @@ #define signed_add_overflows(a, b) \ ((b) > maximum_signed_value_of_type(a) - (a)) +#define unsigned_add_overflows(a, b) \ + ((b) > maximum_unsigned_value_of_type(a) - (a)) + #ifdef __GNUC__ #define TYPEOF(x) (__typeof__(x)) #else |