|
| 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 | +void *memmove(void *dest, const void *src, size_t n); |
| 10 | +size_t strlen(const char *s); |
| 11 | + |
| 12 | +typedef struct va_list_str *va_list; |
| 13 | + |
| 14 | +typedef struct git_vector { |
| 15 | + void **contents; |
| 16 | + size_t length; |
| 17 | +} git_vector; |
| 18 | + |
| 19 | +typedef struct git_buf { |
| 20 | + char *ptr; |
| 21 | + size_t asize, size; |
| 22 | +} git_buf; |
| 23 | + |
| 24 | +int git_vector_insert(git_vector *v, void *element) |
| 25 | +{ |
| 26 | + if (!v) |
| 27 | + __coverity_panic__(); |
| 28 | + |
| 29 | + v->contents = realloc(v->contents, ++v->length); |
| 30 | + if (!v->contents) |
| 31 | + __coverity_panic__(); |
| 32 | + v->contents[v->length] = element; |
| 33 | + |
| 34 | + return 0; |
| 35 | +} |
| 36 | + |
| 37 | +int git_buf_len(const struct git_buf *buf) |
| 38 | +{ |
| 39 | + return strlen(buf->ptr); |
| 40 | +} |
| 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