diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-10-06 12:10:02 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-10-06 12:10:02 -0700 |
commit | 90215bf3008f0986a5a8414d6ea1523148f74826 (patch) | |
tree | 28ccc42636720fd840fca860db90c23fcda3b23b /git-compat-util.h | |
parent | Merge branch 'work/pt/for-junio' of git://repo.or.cz/git/mingw/4msysgit (diff) | |
parent | Documentation/git-clone: describe --mirror more verbosely (diff) | |
download | tgif-90215bf3008f0986a5a8414d6ea1523148f74826.tar.xz |
Merge branch 'maint'
* maint:
Documentation/git-clone: describe --mirror more verbosely
do not depend on signed integer overflow
work around buggy S_ISxxx(m) implementations
xdiff: cast arguments for ctype functions to unsigned char
init: plug tiny one-time memory leak
diffcore-pickaxe.c: remove unnecessary curly braces
t3020 (ls-files-error-unmatch): remove stray '1' from end of file
setup: make sure git dir path is in a permanent buffer
environment.c: remove unused variable
git-svn: fix processing of decorated commit hashes
git-svn: check_cherry_pick should exclude commits already in our history
Documentation/git-svn: discourage "noMetadata"
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 81883e7270..2af8d3edbe 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -28,6 +28,18 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define bitsizeof(x) (CHAR_BIT * sizeof(x)) +#define maximum_signed_value_of_type(a) \ + (INTMAX_MAX >> (bitsizeof(intmax_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. + * + * Requires: a >= 0, typeof(a) equals typeof(b) + */ +#define signed_add_overflows(a, b) \ + ((b) > maximum_signed_value_of_type(a) - (a)) + #ifdef __GNUC__ #define TYPEOF(x) (__typeof__(x)) #else |