diff options
author | Patrick Steinhardt <ps@pks.im> | 2016-02-22 14:43:28 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2016-02-23 11:50:23 +0100 |
commit | f2a554b45e52d7e682f26796e492cd64d8b9a6f4 (patch) | |
tree | 87a209d14f51595cd891d293d86e386fc9d6bf05 /script | |
parent | fb96b28cd9f66998f38a56abb7398ea899c12512 (diff) | |
download | libgit2-f2a554b45e52d7e682f26796e492cd64d8b9a6f4.tar.gz |
coverity: hint git_vector_foreach does not deref NULL contents
Coverity does not comprehend the connection between a vector's
size and the contents pointer, that is that the vector's pointer
is non-NULL when its size is positive. As the vector code should
be reasonably well tested and users are expected to not manually
modify a vector's contents it seems save to assume that the
macros will never dereference a NULL pointer.
Fix Coverity warnings by overriding the foreach macros with
macros that explicitly aborting when (v)->contents is NULL.
Diffstat (limited to 'script')
-rw-r--r-- | script/user_nodefs.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/script/user_nodefs.h b/script/user_nodefs.h index 3d25d92ec..5b0be81a3 100644 --- a/script/user_nodefs.h +++ b/script/user_nodefs.h @@ -25,3 +25,9 @@ #nodef GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) { __coverity_panic__(); } #nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':') + +#nodef git_vector_foreach(v, iter, elem) \ + for ((iter) = 0; (v)->contents != NULL && (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ ) + +#nodef git_vector_rforeach(v, iter, elem) \ + for ((iter) = (v)->length - 1; (v)->contents != NULL && (iter) < SIZE_MAX && ((elem) = (v)->contents[(iter)], 1); (iter)-- ) |