diff --git a/deps/regex/regex_internal.c b/deps/regex/regex_internal.c index 193854cf5..ad57c20dd 100644 --- a/deps/regex/regex_internal.c +++ b/deps/regex/regex_internal.c @@ -32,7 +32,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, #ifdef GAWK #undef MAX /* safety */ -static int +static size_t MAX(size_t a, size_t b) { return (a > b ? a : b); diff --git a/src/branch.c b/src/branch.c index 6b289b12e..45ecca751 100644 --- a/src/branch.c +++ b/src/branch.c @@ -176,7 +176,7 @@ int git_branch_move( return not_a_local_branch(git_reference_name(branch)); if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0 || - (error = git_buf_printf(&old_config_section, "branch.%s", git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0) || + (error = git_buf_printf(&old_config_section, "branch.%s", git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR))) < 0 || (error = git_buf_printf(&new_config_section, "branch.%s", new_branch_name)) < 0) goto done; diff --git a/src/commit.c b/src/commit.c index 7a356c5f9..e2d3d346b 100644 --- a/src/commit.c +++ b/src/commit.c @@ -20,7 +20,7 @@ static void clear_parents(git_commit *commit) { - unsigned int i; + size_t i; for (i = 0; i < commit->parent_ids.length; ++i) { git_oid *parent = git_vector_get(&commit->parent_ids, i); diff --git a/src/config.c b/src/config.c index c7022891d..4439a68a0 100644 --- a/src/config.c +++ b/src/config.c @@ -36,7 +36,7 @@ static void file_internal_free(file_internal *internal) static void config_free(git_config *cfg) { - unsigned int i; + size_t i; file_internal *internal; for(i = 0; i < cfg->files.length; ++i){ @@ -284,7 +284,7 @@ int git_config_add_backend( int git_config_refresh(git_config *cfg) { int error = 0; - unsigned int i; + size_t i; for (i = 0; i < cfg->files.length && !error; ++i) { file_internal *internal = git_vector_get(&cfg->files, i); @@ -312,7 +312,7 @@ int git_config_foreach_match( void *payload) { int ret = 0; - unsigned int i; + size_t i; file_internal *internal; git_config_backend *file; diff --git a/src/diff_output.c b/src/diff_output.c index c0aff6826..b938cc06d 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -390,7 +390,7 @@ static int get_workdir_content( map->data = git__malloc(alloc_len); GITERR_CHECK_ALLOC(map->data); - read_len = p_readlink(path.ptr, map->data, (int)alloc_len); + read_len = p_readlink(path.ptr, map->data, alloc_len); if (read_len < 0) { giterr_set(GITERR_OS, "Failed to read symlink '%s'", file->path); error = -1; diff --git a/src/fileops.c b/src/fileops.c index c1824e812..e33377eac 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -529,7 +529,7 @@ int git_futils_cleanupdir_r(const char *path) git_buf fullpath = GIT_BUF_INIT; futils__rmdir_data data; - if ((error = git_buf_put(&fullpath, path, strlen(path)) < 0)) + if ((error = git_buf_put(&fullpath, path, strlen(path))) < 0) goto clean_up; data.base = ""; diff --git a/src/filter.c b/src/filter.c index f0bfb7980..9f749dcbd 100644 --- a/src/filter.c +++ b/src/filter.c @@ -48,7 +48,8 @@ void git_filters_free(git_vector *filters) int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters) { - unsigned int i, src; + size_t i; + unsigned int src; git_buf *dbuffer[2]; dbuffer[0] = source; diff --git a/src/index.c b/src/index.c index 1ca3b16b2..6290ec4e8 100644 --- a/src/index.c +++ b/src/index.c @@ -317,7 +317,7 @@ void git_index_free(git_index *index) void git_index_clear(git_index *index) { - unsigned int i; + size_t i; assert(index); @@ -786,7 +786,7 @@ int git_index_remove(git_index *index, const char *path, int stage) if (entry != NULL) git_tree_cache_invalidate_path(index->tree, entry->path); - error = git_vector_remove(&index->entries, (unsigned int)position); + error = git_vector_remove(&index->entries, position); if (!error) index_entry_free(entry); @@ -1129,7 +1129,7 @@ int git_index_reuc_remove(git_index *index, size_t position) git_vector_sort(&index->reuc); reuc = git_vector_get(&index->reuc, position); - error = git_vector_remove(&index->reuc, (unsigned int)position); + error = git_vector_remove(&index->reuc, position); if (!error) index_entry_reuc_free(reuc); 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); } diff --git a/src/mwindow.c b/src/mwindow.c index cb2ef78b0..b35503d46 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -33,7 +33,7 @@ static git_mwindow_ctl mem_ctl; void git_mwindow_free_all(git_mwindow_file *mwf) { git_mwindow_ctl *ctl = &mem_ctl; - unsigned int i; + size_t i; if (git_mutex_lock(&git__mwindow_mutex)) { giterr_set(GITERR_THREAD, "unable to lock mwindow mutex"); @@ -115,7 +115,7 @@ static void git_mwindow_scan_lru( static int git_mwindow_close_lru(git_mwindow_file *mwf) { git_mwindow_ctl *ctl = &mem_ctl; - unsigned int i; + size_t i; git_mwindow *lru_w = NULL, *lru_l = NULL, **list = &mwf->windows; /* FIXME: Does this give us any advantage? */ @@ -288,7 +288,7 @@ void git_mwindow_file_deregister(git_mwindow_file *mwf) { git_mwindow_ctl *ctl = &mem_ctl; git_mwindow_file *cur; - unsigned int i; + size_t i; if (git_mutex_lock(&git__mwindow_mutex)) return; diff --git a/src/odb.c b/src/odb.c index 24381e70e..5a0d8871a 100644 --- a/src/odb.c +++ b/src/odb.c @@ -499,7 +499,7 @@ int git_odb_open(git_odb **out, const char *objects_dir) static void odb_free(git_odb *db) { - unsigned int i; + size_t i; for (i = 0; i < db->backends.length; ++i) { backend_internal *internal = git_vector_get(&db->backends, i); @@ -527,7 +527,7 @@ void git_odb_free(git_odb *db) int git_odb_exists(git_odb *db, const git_oid *id) { git_odb_object *object; - unsigned int i; + size_t i; bool found = false; bool refreshed = false; @@ -577,7 +577,7 @@ int git_odb__read_header_or_object( git_odb_object **out, size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id) { - unsigned int i; + size_t i; int error = GIT_ENOTFOUND; git_odb_object *object; @@ -619,7 +619,7 @@ int git_odb__read_header_or_object( int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id) { - unsigned int i; + size_t i; int error; bool refreshed = false; git_rawobj raw; @@ -664,7 +664,7 @@ attempt_lookup: int git_odb_read_prefix( git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len) { - unsigned int i; + size_t i; int error = GIT_ENOTFOUND; git_oid found_full_oid = {{0}}; git_rawobj raw; @@ -743,7 +743,7 @@ int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload) int git_odb_write( git_oid *oid, git_odb *db, const void *data, size_t len, git_otype type) { - unsigned int i; + size_t i; int error = GIT_ERROR; git_odb_stream *stream; @@ -785,7 +785,7 @@ int git_odb_write( int git_odb_open_wstream( git_odb_stream **stream, git_odb *db, size_t size, git_otype type) { - unsigned int i; + size_t i; int error = GIT_ERROR; assert(stream && db); @@ -812,7 +812,7 @@ int git_odb_open_wstream( int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid) { - unsigned int i; + size_t i; int error = GIT_ERROR; assert(stream && db); @@ -833,7 +833,7 @@ int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oi int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_transfer_progress_callback progress_cb, void *progress_payload) { - unsigned int i; + size_t i; int error = GIT_ERROR; assert(out && db); @@ -864,7 +864,7 @@ void *git_odb_backend_malloc(git_odb_backend *backend, size_t len) int git_odb_refresh(struct git_odb *db) { - unsigned int i; + size_t i; assert(db); for (i = 0; i < db->backends.length; ++i) { diff --git a/src/odb_pack.c b/src/odb_pack.c index 7e6828eae..7240a4ac7 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -195,7 +195,7 @@ static int packfile_load__cb(void *_data, git_buf *path) struct pack_backend *backend = (struct pack_backend *)_data; struct git_pack_file *pack; int error; - unsigned int i; + size_t i; if (git__suffixcmp(path->ptr, ".idx") != 0) return 0; /* not an index */ @@ -222,7 +222,7 @@ static int pack_entry_find_inner( const git_oid *oid, struct git_pack_file *last_found) { - unsigned int i; + size_t i; if (last_found && git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0) @@ -266,7 +266,7 @@ static unsigned pack_entry_find_prefix_inner( struct git_pack_file *last_found) { int error; - unsigned int i; + size_t i; unsigned found = 0; if (last_found) { @@ -510,7 +510,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out, static void pack_backend__free(git_odb_backend *_backend) { struct pack_backend *backend; - unsigned int i; + size_t i; assert(_backend); diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 5f5d42f66..f00bd72a0 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -769,7 +769,7 @@ static int packed_remove_loose( refdb_fs_backend *backend, git_vector *packing_list) { - unsigned int i; + size_t i; git_buf full_path = GIT_BUF_INIT; int failed = 0; @@ -811,7 +811,7 @@ static int packed_remove_loose( static int packed_write(refdb_fs_backend *backend) { git_filebuf pack_file = GIT_FILEBUF_INIT; - unsigned int i; + size_t i; git_buf pack_file_path = GIT_BUF_INIT; git_vector packing_list; unsigned int total_refs; diff --git a/src/reflog.c b/src/reflog.c index 432680b99..8c133fe53 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -163,7 +163,7 @@ fail: void git_reflog_free(git_reflog *reflog) { - unsigned int i; + size_t i; git_reflog_entry *entry; if (reflog == NULL) diff --git a/src/refs.c b/src/refs.c index 41c6fd838..dde2f51a9 100644 --- a/src/refs.c +++ b/src/refs.c @@ -440,6 +440,7 @@ int git_reference_rename( git_oid *oid; const char *symbolic; int error = 0; + int reference_has_log; *out = NULL; @@ -465,11 +466,13 @@ int git_reference_rename( return -1; /* Check if we have to update HEAD. */ - if ((should_head_be_updated = git_branch_is_head(ref)) < 0) + if ((error = git_branch_is_head(ref)) < 0) goto on_error; + should_head_be_updated = (error > 0); + /* Now delete the old ref and save the new one. */ - if (git_refdb_delete(ref->db, ref) < 0) + if ((error = git_refdb_delete(ref->db, ref)) < 0) goto on_error; /* Save the new reference. */ @@ -477,14 +480,18 @@ int git_reference_rename( goto rollback; /* Update HEAD it was poiting to the reference being renamed. */ - if (should_head_be_updated && git_repository_set_head(ref->db->repo, new_name) < 0) { + if (should_head_be_updated && (error = git_repository_set_head(ref->db->repo, new_name)) < 0) { giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference"); goto on_error; } /* Rename the reflog file, if it exists. */ - if (git_reference_has_log(ref) && - (error = git_reflog_rename(ref, new_name)) < 0) + reference_has_log = git_reference_has_log(ref); + if (reference_has_log < 0) { + error = reference_has_log; + goto on_error; + } + if (reference_has_log && (error = git_reflog_rename(ref, new_name)) < 0) goto on_error; *out = result; diff --git a/src/remote.c b/src/remote.c index 21ca6ecdb..a6f62d6a5 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1254,7 +1254,7 @@ static int rename_fetch_refspecs( goto cleanup; /* Is it an in-memory remote? */ - if (remote->name == '\0') { + if (!remote->name) { error = (callback(git_buf_cstr(&serialized), payload) < 0) ? GIT_EUSER : 0; goto cleanup; } diff --git a/src/revparse.c b/src/revparse.c index 8a45889bb..1518a7c3c 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -511,8 +511,8 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) while (!(error = git_revwalk_next(&oid, walk))) { - if ((error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT) < 0) && - (error != GIT_ENOTFOUND)) + error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT); + if ((error < 0) && (error != GIT_ENOTFOUND)) return -1; if (!regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) { @@ -635,7 +635,7 @@ static int extract_how_many(int *n, const char *spec, size_t *pos) } while (spec[(*pos)] == kind && kind == '~'); if (git__isdigit(spec[*pos])) { - if ((git__strtol32(&parsed, spec + *pos, &end_ptr, 10) < 0) < 0) + if (git__strtol32(&parsed, spec + *pos, &end_ptr, 10) < 0) return GIT_EINVALIDSPEC; accumulated += (parsed - 1); diff --git a/src/submodule.c b/src/submodule.c index c02061376..957766dfc 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -1497,7 +1497,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm) if (untracked > 0) *status |= GIT_SUBMODULE_STATUS_WD_UNTRACKED; - if ((git_diff_num_deltas(diff) - untracked) > 0) + if (git_diff_num_deltas(diff) != untracked) *status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED; git_diff_list_free(diff); diff --git a/src/transports/local.c b/src/transports/local.c index 5ed7b4519..ce89bb213 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -124,7 +124,7 @@ static int store_refs(transport_local *t) assert(t); if (git_reference_list(&ref_names, t->repo, GIT_REF_LISTALL) < 0 || - git_vector_init(&t->refs, (unsigned int)ref_names.count, NULL) < 0) + git_vector_init(&t->refs, ref_names.count, NULL) < 0) goto on_error; /* Sort the references first */ diff --git a/src/transports/smart.c b/src/transports/smart.c index e820488f6..bfcce0c08 100644 --- a/src/transports/smart.c +++ b/src/transports/smart.c @@ -24,7 +24,7 @@ static int git_smart__recv_cb(gitno_buffer *buf) buf->offset += bytes_read; if (t->packetsize_cb) - t->packetsize_cb((int)bytes_read, t->packetsize_payload); + t->packetsize_cb(bytes_read, t->packetsize_payload); return (int)(buf->offset - old_len); } diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c index c653ad504..8acedeb49 100644 --- a/src/transports/smart_protocol.c +++ b/src/transports/smart_protocol.c @@ -454,7 +454,7 @@ int git_smart__download_pack( /* We might have something in the buffer already from negotiate_fetch */ if (t->buffer.offset > 0) - t->packetsize_cb((int)t->buffer.offset, t->packetsize_payload); + t->packetsize_cb(t->buffer.offset, t->packetsize_payload); } if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||