Blame script/user_model.c

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
void *realloc(void *ptr, size_t size);
Packit Service 20376f
void *memmove(void *dest, const void *src, size_t n);
Packit Service 20376f
size_t strlen(const char *s);
Packit Service 20376f
Packit Service 20376f
typedef struct va_list_str *va_list;
Packit Service 20376f
Packit Service 20376f
typedef struct git_vector {
Packit Service 20376f
	void **contents;
Packit Service 20376f
	size_t length;
Packit Service 20376f
} git_vector;
Packit Service 20376f
Packit Service 20376f
typedef struct git_buf {
Packit Service 20376f
	char *ptr;
Packit Service 20376f
	size_t asize, size;
Packit Service 20376f
} git_buf;
Packit Service 20376f
Packit Service 20376f
int git_vector_insert(git_vector *v, void *element)
Packit Service 20376f
{
Packit Service 20376f
	if (!v)
Packit Service 20376f
		__coverity_panic__();
Packit Service 20376f
Packit Service 20376f
	v->contents = realloc(v->contents, ++v->length);
Packit Service 20376f
	if (!v->contents)
Packit Service 20376f
		__coverity_panic__();
Packit Service 20376f
	v->contents[v->length] = element;
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_buf_len(const struct git_buf *buf)
Packit Service 20376f
{
Packit Service 20376f
	return strlen(buf->ptr);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
Packit Service 20376f
{
Packit Service 20376f
    char ch, *s;
Packit Service 20376f
    size_t len;
Packit Service 20376f
Packit Service 20376f
    __coverity_string_null_sink__(format);
Packit Service 20376f
    __coverity_string_size_sink__(format);
Packit Service 20376f
Packit Service 20376f
    ch = *format;
Packit Service 20376f
    ch = *(char *)ap;
Packit Service 20376f
Packit Service 20376f
    buf->ptr = __coverity_alloc__(len);
Packit Service 20376f
    __coverity_writeall__(buf->ptr);
Packit Service 20376f
    buf->size = len;
Packit Service 20376f
Packit Service 20376f
    return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_buf_put(git_buf *buf, const char *data, size_t len)
Packit Service 20376f
{
Packit Service 20376f
    buf->ptr = __coverity_alloc__(buf->size + len + 1);
Packit Service 20376f
    memmove(buf->ptr + buf->size, data, len);
Packit Service 20376f
    buf->size += len;
Packit Service 20376f
    buf->ptr[buf->size + len] = 0;
Packit Service 20376f
    return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_buf_set(git_buf *buf, const void *data, size_t len)
Packit Service 20376f
{
Packit Service 20376f
    buf->ptr = __coverity_alloc__(len + 1);
Packit Service 20376f
    memmove(buf->ptr, data, len);
Packit Service 20376f
    buf->size = len + 1;
Packit Service 20376f
    return 0;
Packit Service 20376f
}