Skip to content

Commit b1e2862

Browse files
authored
Merge pull request libgit2#4950 from libgit2/ethomson/warnings
Clean up some warnings
2 parents f56634f + fac0883 commit b1e2862

29 files changed

+124
-60
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ IF (MSVC)
164164
# /O1 - Optimize for size
165165
SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
166166

167+
# /IGNORE:4221 - Ignore empty compilation units
168+
SET(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221")
169+
167170
# /DYNAMICBASE - Address space load randomization (ASLR)
168171
# /NXCOMPAT - Data execution prevention (DEP)
169172
# /LARGEADDRESSAWARE - >2GB user address space on x86

src/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static bool find_hunk_linenum(
138138

139139
static int update_hunk(
140140
patch_image *image,
141-
unsigned int linenum,
141+
size_t linenum,
142142
patch_image *preimage,
143143
patch_image *postimage)
144144
{

src/attr_file.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "attrcache.h"
1313
#include "git2/blob.h"
1414
#include "git2/tree.h"
15+
#include "blob.h"
1516
#include "index.h"
1617
#include <ctype.h>
1718

@@ -119,14 +120,18 @@ int git_attr_file__load(
119120
break;
120121
case GIT_ATTR_FILE__FROM_INDEX: {
121122
git_oid id;
123+
git_off_t blobsize;
122124

123125
if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
124126
(error = git_blob_lookup(&blob, repo, &id)) < 0)
125127
return error;
126128

127129
/* Do not assume that data straight from the ODB is NULL-terminated;
128130
* copy the contents of a file to a buffer to work on */
129-
git_buf_put(&content, git_blob_rawcontent(blob), git_blob_rawsize(blob));
131+
blobsize = git_blob_rawsize(blob);
132+
133+
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
134+
git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
130135
break;
131136
}
132137
case GIT_ATTR_FILE__FROM_FILE: {

src/blame.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ static int hunk_cmp(const void *_a, const void *_b)
4141
git_blame_hunk *a = (git_blame_hunk*)_a,
4242
*b = (git_blame_hunk*)_b;
4343

44-
return a->final_start_line_number - b->final_start_line_number;
44+
if (a->final_start_line_number > b->final_start_line_number)
45+
return 1;
46+
else if (a->final_start_line_number < b->final_start_line_number)
47+
return -1;
48+
else
49+
return 0;
4550
}
4651

4752
static bool hunk_ends_at_or_before_line(git_blame_hunk *hunk, size_t line)

src/blob.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ git_off_t git_blob_rawsize(const git_blob *blob)
3636

3737
int git_blob__getbuf(git_buf *buffer, git_blob *blob)
3838
{
39-
return git_buf_set(
40-
buffer,
41-
git_blob_rawcontent(blob),
42-
git_blob_rawsize(blob));
39+
git_off_t size = git_blob_rawsize(blob);
40+
41+
GIT_ERROR_CHECK_BLOBSIZE(size);
42+
return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size);
4343
}
4444

4545
void git_blob__free(void *_blob)
@@ -389,12 +389,14 @@ int git_blob_create_fromstream_commit(git_oid *out, git_writestream *_stream)
389389
int git_blob_is_binary(const git_blob *blob)
390390
{
391391
git_buf content = GIT_BUF_INIT;
392+
git_off_t size;
392393

393394
assert(blob);
394395

396+
size = git_blob_rawsize(blob);
397+
395398
git_buf_attach_notowned(&content, git_blob_rawcontent(blob),
396-
min(git_blob_rawsize(blob),
397-
GIT_FILTER_BYTES_TO_CHECK_NUL));
399+
(size_t)min(size, GIT_FILTER_BYTES_TO_CHECK_NUL));
398400
return git_buf_text_is_binary(&content);
399401
}
400402

src/blob.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ struct git_blob {
2727
unsigned int raw:1;
2828
};
2929

30+
#define GIT_ERROR_CHECK_BLOBSIZE(n) \
31+
do { \
32+
if (!git__is_sizet(n)) { \
33+
git_error_set(GIT_ERROR_NOMEMORY, "blob contents too large to fit in memory"); \
34+
return -1; \
35+
} \
36+
} while(0)
37+
3038
void git_blob__free(void *blob);
3139
int git_blob__parse(void *blob, git_odb_object *obj);
3240
int git_blob__parse_raw(void *blob, const char *data, size_t size);

src/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ int git_buf_decode_base85(
440440

441441
acc += de;
442442

443-
cnt = (output_len < 4) ? output_len : 4;
443+
cnt = (output_len < 4) ? (int)output_len : 4;
444444
output_len -= cnt;
445445
do {
446446
acc = (acc << 8) | (acc >> 24);

src/delta.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int lookup_index_alloc(
138138
*out = git__malloc(index_len);
139139
GIT_ERROR_CHECK_ALLOC(*out);
140140

141-
*out_len = index_len;
141+
*out_len = (unsigned long)index_len;
142142
return 0;
143143
}
144144

@@ -286,6 +286,13 @@ int git_delta_create_from_index(
286286
if (!trg_buf || !trg_size)
287287
return 0;
288288

289+
if (index->src_size > UINT_MAX ||
290+
trg_size > UINT_MAX ||
291+
max_size > (UINT_MAX - MAX_OP_SIZE - 1)) {
292+
git_error_set(GIT_ERROR_INVALID, "buffer sizes too large for delta processing");
293+
return -1;
294+
}
295+
289296
bufpos = 0;
290297
bufsize = 8192;
291298
if (max_size && bufsize >= max_size)
@@ -294,15 +301,15 @@ int git_delta_create_from_index(
294301
GIT_ERROR_CHECK_ALLOC(buf);
295302

296303
/* store reference buffer size */
297-
i = index->src_size;
304+
i = (unsigned int)index->src_size;
298305
while (i >= 0x80) {
299306
buf[bufpos++] = i | 0x80;
300307
i >>= 7;
301308
}
302309
buf[bufpos++] = i;
303310

304311
/* store target buffer size */
305-
i = trg_size;
312+
i = (unsigned int)trg_size;
306313
while (i >= 0x80) {
307314
buf[bufpos++] = i | 0x80;
308315
i >>= 7;
@@ -423,7 +430,7 @@ int git_delta_create_from_index(
423430
void *tmp = buf;
424431
bufsize = bufsize * 3 / 2;
425432
if (max_size && bufsize >= max_size)
426-
bufsize = max_size + MAX_OP_SIZE + 1;
433+
bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1);
427434
if (max_size && bufpos > max_size)
428435
break;
429436
buf = git__realloc(buf, bufsize);

src/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static int find_unique_abbrev_size(
366366
int *out,
367367
git_repository *repo,
368368
const git_oid *oid_in,
369-
int abbreviated_size)
369+
unsigned int abbreviated_size)
370370
{
371371
size_t size = abbreviated_size;
372372
git_odb *odb;
@@ -401,7 +401,7 @@ static int show_suffix(
401401
int depth,
402402
git_repository *repo,
403403
const git_oid* id,
404-
size_t abbrev_size)
404+
unsigned int abbrev_size)
405405
{
406406
int error, size = 0;
407407

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
386386

387387
for (i = 0; i < GIT_OID_RAWSZ; i++) {
388388
carry += result->id[i] + hash.id[i];
389-
result->id[i] = carry;
389+
result->id[i] = (unsigned char)carry;
390390
carry >>= 8;
391391
}
392392

0 commit comments

Comments
 (0)