summaryrefslogtreecommitdiff
path: root/credential-store.c
diff options
context:
space:
mode:
authorElia Pinto <gitter.spiros@gmail.com>2015-04-30 12:44:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-05 22:26:48 (GMT)
commit89c855ed3cbe64bea93ea081d0e96077e9ee8517 (patch)
tree72ce4c2b43a79f93f955ceafd7cf8f4ebdab6fb7 /credential-store.c
parentfdf96a20acf96a6ac538df8113b2aafd6ed71d50 (diff)
downloadgit-89c855ed3cbe64bea93ea081d0e96077e9ee8517.zip
git-89c855ed3cbe64bea93ea081d0e96077e9ee8517.tar.gz
git-89c855ed3cbe64bea93ea081d0e96077e9ee8517.tar.bz2
git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array
To get number of elements in an array git use the ARRAY_SIZE macro defined as: #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) The problem with it is a possibility of mistakenly passing to it a pointer instead an array. The ARRAY_SIZE macro as conventionally defined does not provide good type-safety and the open-coded approach is more fragile, more verbose and provides no improvement in type-safety. Use instead a different but compatible ARRAY_SIZE() macro, which will also break compile if you try to use it on a pointer. This implemention revert to the original code if the compiler doesn't know the typeof and __builtin_types_compatible_p GCC extensions. This can ensure our code is robust to changes, without needing a gratuitous macro or constant. A similar ARRAY_SIZE implementation also exists in the linux kernel. Credits to Rusty Russell and his ccan library. Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'credential-store.c')
0 files changed, 0 insertions, 0 deletions