summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-06-07 09:17:52 +0200
committerPatrick Steinhardt <ps@pks.im>2016-06-07 09:20:51 +0200
commit956f1e2387a807a2e3ec25e75d04050c705ab3b9 (patch)
tree9ba2b82e2821e2ffe27b5ce1f849149308232599
parentf0ee795ccb552b87637c7973ac64f64437baa041 (diff)
downloadlibgit2-956f1e2387a807a2e3ec25e75d04050c705ab3b9.tar.gz
coverity: add user model
The static analysis engine coverity allows for user models overriding how it treats functions when analyzing code. Like this, one can greatly reduce the rate of false positives and thus make it easier to spot actual errors. Add a user model that overrides function models for `git_buf_len` and `git_vector_insert`, which together amount for a majority of false positives.
-rw-r--r--script/user_model.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/script/user_model.c b/script/user_model.c
new file mode 100644
index 000000000..3c00b6984
--- /dev/null
+++ b/script/user_model.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+void *realloc(void *ptr, size_t size);
+size_t strlen(const char *s);
+
+typedef struct git_vector {
+ void **contents;
+ size_t length;
+} git_vector;
+
+typedef struct git_buf {
+ char *ptr;
+ size_t asize, size;
+} git_buf;
+
+int git_vector_insert(git_vector *v, void *element)
+{
+ if (!v)
+ __coverity_panic__();
+
+ v->contents = realloc(v->contents, ++v->length);
+ if (!v->contents)
+ __coverity_panic__();
+ v->contents[v->length] = element;
+
+ return 0;
+}
+
+int git_buf_len(const struct git_buf *buf)
+{
+ return strlen(buf->ptr);
+}