Commit 3f035860 by Vicent Martí

misc: Fix warnings from PVS Studio trial

parent 763b8381
......@@ -96,9 +96,9 @@ typedef enum {
typedef struct {
git_oid oid;
char *path;
uint16_t mode;
git_off_t size;
unsigned int flags;
uint16_t mode;
} git_diff_file;
/**
......
......@@ -415,7 +415,7 @@ int git_attr_cache__push_file(
if (parse && (error = parse(repo, content, file)) < 0)
goto finish;
git_strmap_insert(cache->files, file->key, file, error);
git_strmap_insert(cache->files, file->key, file, error); //-V595
if (error > 0)
error = 0;
......
......@@ -144,8 +144,9 @@ int git_buf_puts(git_buf *buf, const char *string)
int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
{
int len;
const size_t expected_size = buf->size + (strlen(format) * 2);
ENSURE_SIZE(buf, buf->size + (strlen(format) * 2));
ENSURE_SIZE(buf, expected_size);
while (1) {
va_list args;
......
......@@ -69,7 +69,7 @@ void *git_cache_try_store(git_cache *cache, void *_entry)
git_cached_obj *entry = _entry;
uint32_t hash;
memcpy(&hash, &entry->oid, sizeof(hash));
memcpy(&hash, &entry->oid, sizeof(uint32_t));
/* increase the refcount on this object, because
* the cache now owns it */
......
......@@ -531,7 +531,7 @@ static int parse_date_basic(const char *date, git_time_t *timestamp, int *offset
/* mktime uses local timezone */
*timestamp = tm_to_time_t(&tm);
if (*offset == -1)
*offset = ((time_t)*timestamp - mktime(&tm)) / 60;
*offset = (int)((time_t)*timestamp - mktime(&tm)) / 60;
if (*timestamp == (git_time_t)-1)
return -1;
......
......@@ -467,7 +467,7 @@ static char pick_suffix(int mode)
{
if (S_ISDIR(mode))
return '/';
else if (mode & 0100)
else if (mode & 0100) //-V536
/* in git, modes are very regular, so we must have 0100755 mode */
return '*';
else
......
......@@ -292,11 +292,13 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
{
int error;
struct git_pack_header hdr;
size_t processed = stats->processed;
size_t processed;
git_mwindow_file *mwf = &idx->pack->mwf;
assert(idx && data && stats);
processed = stats->processed;
if (git_filebuf_write(&idx->pack_file, data, size) < 0)
return -1;
......
......@@ -125,7 +125,7 @@ static int note_write(git_oid *out, git_repository *repo,
return error;
}
error = git_treebuilder_insert(&entry, tb, target + fanout, &oid, 0100644);
error = git_treebuilder_insert(&entry, tb, target + fanout, &oid, 0100644); //-V536
if (error < 0) {
/* libgit2 doesn't support object removal (gc) yet */
/* we leave an orphaned blob object behind - TODO */
......@@ -154,7 +154,7 @@ static int note_write(git_oid *out, git_repository *repo,
if (error < 0)
return error;
error = git_treebuilder_insert(NULL, tb, subtree, &oid, 0040000);
error = git_treebuilder_insert(NULL, tb, subtree, &oid, 0040000); //-V536
if (error < 0) {
git_treebuilder_free(tb);
return error;
......
......@@ -337,13 +337,16 @@ int git_remote_update_tips(git_remote *remote, int (*cb)(const char *refname, co
unsigned int i = 0;
git_buf refname = GIT_BUF_INIT;
git_oid old;
git_vector *refs = &remote->refs;
git_vector *refs;
git_remote_head *head;
git_reference *ref;
struct git_refspec *spec = &remote->fetch;
struct git_refspec *spec;
assert(remote);
refs = &remote->refs;
spec = &remote->fetch;
if (refs->length == 0)
return 0;
......
......@@ -506,7 +506,7 @@ static int handle_linear_syntax(git_object **out, git_object *obj, const char *m
}
/* "~" is the same as "~1" */
if (strlen(movement) == 0) {
if (*movement == '\0') {
n = 1;
} else {
git__strtol32(&n, movement, NULL, 0);
......
......@@ -69,7 +69,7 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char
return NULL;
}
if (end == NULL || end + 1 == '\0')
if (end == NULL || *end + 1 == '\0')
return tree;
ptr = end + 1;
......
......@@ -22,7 +22,7 @@ static int valid_attributes(const int attributes)
static int valid_entry_name(const char *filename)
{
return strlen(filename) > 0 && strchr(filename, '/') == NULL;
return *filename != '\0' && strchr(filename, '/') == NULL;
}
static int entry_sort_cmp(const void *a, const void *b)
......
......@@ -414,7 +414,7 @@ int p_mkstemp(char *tmp_path)
return -1;
#endif
return p_creat(tmp_path, 0744);
return p_creat(tmp_path, 0744); //-V536
}
int p_setenv(const char* name, const char* value, int overwrite)
......
......@@ -8,7 +8,7 @@ void test_core_filebuf__0(void)
int fd;
char test[] = "test", testlock[] = "test.lock";
fd = p_creat(testlock, 0744);
fd = p_creat(testlock, 0744); //-V536
cl_must_pass(fd);
cl_must_pass(p_close(fd));
......@@ -27,7 +27,7 @@ void test_core_filebuf__1(void)
int fd;
char test[] = "test";
fd = p_creat(test, 0666);
fd = p_creat(test, 0666); //-V536
cl_must_pass(fd);
cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
cl_must_pass(p_close(fd));
......
......@@ -33,7 +33,7 @@ static void copy_file(const char *src, const char *dst)
cl_git_pass(git_futils_readbuffer(&source_buf, src));
dst_fd = git_futils_creat_withpath(dst, 0777, 0666);
dst_fd = git_futils_creat_withpath(dst, 0777, 0666); //-V536
if (dst_fd < 0)
goto cleanup;
......
......@@ -63,14 +63,14 @@ void test_object_tree_write__subtree(void)
//create subtree
cl_git_pass(git_treebuilder_create(&builder, NULL));
cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); //-V536
cl_git_pass(git_treebuilder_write(&subtree_id, g_repo, builder));
git_treebuilder_free(builder);
// create parent tree
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_create(&builder, tree));
cl_git_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000));
cl_git_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000)); //-V536
cl_git_pass(git_treebuilder_write(&id_hiearar, g_repo, builder));
git_treebuilder_free(builder);
git_tree_free(tree);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment