diff options
author | Arkadiy Shapkin <ashapkin@artec-group.com> | 2013-03-17 04:46:46 +0400 |
---|---|---|
committer | Arkadiy Shapkin <ashapkin@artec-group.com> | 2013-03-18 03:30:26 +0400 |
commit | 10c06114cbb1c384b7de3cca6d6601ee750f5178 (patch) | |
tree | 05b4c66610443dd41b50114480da9e8b7e99a123 /src/indexer.c | |
parent | a5f6138407efb6d8866fe8de5aac13454aefcd82 (diff) | |
download | libgit2-10c06114cbb1c384b7de3cca6d6601ee750f5178.tar.gz |
Several warnings detected by static code analyzer fixed
Implicit type conversion argument of function to size_t type
Suspicious sequence of types castings: size_t -> int -> size_t
Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)'
Unsigned type is never < 0
Diffstat (limited to 'src/indexer.c')
-rw-r--r-- | src/indexer.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/indexer.c b/src/indexer.c index c7e142baf..2cfbd3a5a 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -415,6 +415,8 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz } if (!idx->parsed_header) { + unsigned int total_objects; + if ((unsigned)idx->pack->mwf.size < sizeof(hdr)) return 0; @@ -427,20 +429,24 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz /* for now, limit to 2^32 objects */ assert(idx->nr_objects == (size_t)((unsigned int)idx->nr_objects)); + if (idx->nr_objects == (size_t)((unsigned int)idx->nr_objects)) + total_objects = (unsigned int)idx->nr_objects; + else + total_objects = UINT_MAX; idx->pack->idx_cache = git_oidmap_alloc(); GITERR_CHECK_ALLOC(idx->pack->idx_cache); idx->pack->has_cache = 1; - if (git_vector_init(&idx->objects, (unsigned int)idx->nr_objects, objects_cmp) < 0) + if (git_vector_init(&idx->objects, total_objects, objects_cmp) < 0) return -1; - if (git_vector_init(&idx->deltas, (unsigned int)(idx->nr_objects / 2), NULL) < 0) + if (git_vector_init(&idx->deltas, total_objects / 2, NULL) < 0) return -1; stats->received_objects = 0; processed = stats->indexed_objects = 0; - stats->total_objects = (unsigned int)idx->nr_objects; + stats->total_objects = total_objects; do_progress_callback(idx, stats); } |