Skip to content

Commit 956f1e2

Browse files
committed
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.
1 parent f0ee795 commit 956f1e2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

script/user_model.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
void *realloc(void *ptr, size_t size);
9+
size_t strlen(const char *s);
10+
11+
typedef struct git_vector {
12+
void **contents;
13+
size_t length;
14+
} git_vector;
15+
16+
typedef struct git_buf {
17+
char *ptr;
18+
size_t asize, size;
19+
} git_buf;
20+
21+
int git_vector_insert(git_vector *v, void *element)
22+
{
23+
if (!v)
24+
__coverity_panic__();
25+
26+
v->contents = realloc(v->contents, ++v->length);
27+
if (!v->contents)
28+
__coverity_panic__();
29+
v->contents[v->length] = element;
30+
31+
return 0;
32+
}
33+
34+
int git_buf_len(const struct git_buf *buf)
35+
{
36+
return strlen(buf->ptr);
37+
}

0 commit comments

Comments
 (0)