misc: Fix warnings from PVS Studio trial
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
diff --git a/include/git2/diff.h b/include/git2/diff.h
index a0e8ad6..46b80d8 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -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;
/**
diff --git a/src/attr.c b/src/attr.c
index fb66511..6fbd005 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -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;
diff --git a/src/buffer.c b/src/buffer.c
index 783a36e..04aaec3 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;
diff --git a/src/cache.c b/src/cache.c
index 31da3c3..f8d8940 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -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 */
diff --git a/src/date.c b/src/date.c
index 658b09e..f0e637a 100644
--- a/src/date.c
+++ b/src/date.c
@@ -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;
diff --git a/src/diff_output.c b/src/diff_output.c
index 5ffa641..1c65e1b 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -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
diff --git a/src/indexer.c b/src/indexer.c
index f0e0a63..5ae66c9 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -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;
diff --git a/src/notes.c b/src/notes.c
index 84ad940..e87ea65 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -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;
diff --git a/src/remote.c b/src/remote.c
index 8d60761..00e108a 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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;
diff --git a/src/revparse.c b/src/revparse.c
index dd8476e..1e6b710 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -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);
diff --git a/src/tree-cache.c b/src/tree-cache.c
index ebc2c68..8d186d2 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -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;
diff --git a/src/tree.c b/src/tree.c
index 92b1b1e..d575dc8 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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)
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index f0441df..37956af 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -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)
diff --git a/tests-clar/core/filebuf.c b/tests-clar/core/filebuf.c
index eab8a26..4451c01 100644
--- a/tests-clar/core/filebuf.c
+++ b/tests-clar/core/filebuf.c
@@ -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));
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 3436f8d..a535d68 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -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;
diff --git a/tests-clar/object/tree/write.c b/tests-clar/object/tree/write.c
index 3911f6f..e6dc549 100644
--- a/tests-clar/object/tree/write.c
+++ b/tests-clar/object/tree/write.c
@@ -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);