Skip to content

Commit 4d8fe1c

Browse files
committed
coverity: model functions printing into git_buf
The `git_buf` structure seems to be too complicated to correctly grasp for Coverity. As such, add simpler models trying to guide Coverity and remove false positives related to these functions.
1 parent 956f1e2 commit 4d8fe1c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

script/user_model.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
*/
77

88
void *realloc(void *ptr, size_t size);
9+
void *memmove(void *dest, const void *src, size_t n);
910
size_t strlen(const char *s);
1011

12+
typedef struct va_list_str *va_list;
13+
1114
typedef struct git_vector {
1215
void **contents;
1316
size_t length;
@@ -35,3 +38,38 @@ int git_buf_len(const struct git_buf *buf)
3538
{
3639
return strlen(buf->ptr);
3740
}
41+
42+
int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
43+
{
44+
char ch, *s;
45+
size_t len;
46+
47+
__coverity_string_null_sink__(format);
48+
__coverity_string_size_sink__(format);
49+
50+
ch = *format;
51+
ch = *(char *)ap;
52+
53+
buf->ptr = __coverity_alloc__(len);
54+
__coverity_writeall__(buf->ptr);
55+
buf->size = len;
56+
57+
return 0;
58+
}
59+
60+
int git_buf_put(git_buf *buf, const char *data, size_t len)
61+
{
62+
buf->ptr = __coverity_alloc__(buf->size + len + 1);
63+
memmove(buf->ptr + buf->size, data, len);
64+
buf->size += len;
65+
buf->ptr[buf->size + len] = 0;
66+
return 0;
67+
}
68+
69+
int git_buf_set(git_buf *buf, const void *data, size_t len)
70+
{
71+
buf->ptr = __coverity_alloc__(len + 1);
72+
memmove(buf->ptr, data, len);
73+
buf->size = len + 1;
74+
return 0;
75+
}

0 commit comments

Comments
 (0)