Skip to content

Fix some issues reported by Coverity #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 9, 2019
Merged
1 change: 1 addition & 0 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static void err(struct add_p_state *s, const char *fmt, ...)
vfprintf(stderr, fmt, args);
fputs(s->s.reset_color, stderr);
fputc('\n', stderr);
va_end(args);
}

static void setup_child_process(struct child_process *cp,
Expand Down
5 changes: 4 additions & 1 deletion builtin/bisect--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
write_file(git_path_bisect_start(), "%s\n", start_head.buf);

if (no_checkout) {
get_oid(start_head.buf, &oid);
if (get_oid(start_head.buf, &oid) < 0) {
retval = error(_("invalid ref: '%s'"), start_head.buf);
goto finish;
}
if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR)) {
retval = -1;
Expand Down
3 changes: 2 additions & 1 deletion builtin/rebase--interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static int get_revision_ranges(const char *upstream, const char *onto,
const char *shortrev;
struct object_id rev_oid;

get_oid(base_rev, &rev_oid);
if (get_oid(base_rev, &rev_oid) < 0)
return error(_("invalid rev '%s'"), base_rev);
shortrev = find_unique_abbrev(&rev_oid, DEFAULT_ABBREV);

*shortrevisions = xstrfmt("%s..%s", shortrev, shorthead);
Expand Down
2 changes: 1 addition & 1 deletion builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ static int rebase_config(const char *var, const char *value, void *data)
if (git_config_bool(var, value))
opts->flags |= REBASE_DIFFSTAT;
else
opts->flags &= !REBASE_DIFFSTAT;
opts->flags &= ~REBASE_DIFFSTAT;
return 0;
}

Expand Down
6 changes: 4 additions & 2 deletions ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ then
CI_OS_NAME="$(echo "$AGENT_OS" | tr A-Z a-z)"
test darwin != "$CI_OS_NAME" || CI_OS_NAME=osx
CI_REPO_SLUG="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
jobs=10
if test -n "$MSVC"
then
CC=compat/vcbuild/scripts/clink.pl
jobname=windows-msvc
jobs=4
fi
CC="${CC:-gcc}"

Expand All @@ -132,9 +134,9 @@ then
}

BREW_INSTALL_PACKAGES=gcc@8
export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save"
export GIT_PROVE_OPTS="--timer --jobs $jobs --state=failed,slow,save"
export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml"
MAKEFLAGS="$MAKEFLAGS --jobs=10"
MAKEFLAGS="$MAKEFLAGS --jobs=$jobs"
test windows_nt != "$CI_OS_NAME" ||
GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
else
Expand Down
9 changes: 5 additions & 4 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ static struct fsentry *fsentry_create_list(struct fscache *cache, const struct f
return list;

Error:
errno = (status == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(status);
trace_printf_key(&trace_fscache, "fscache: error(%d) unable to query directory contents '%.*s'\n",
errno, dir->len, dir->name);
trace_printf_key(&trace_fscache, "fscache: status(%ld) unable to query directory contents '%.*s'\n",
status, dir->len, dir->name);
CloseHandle(h);
fsentry_release(list);
return NULL;
Expand Down Expand Up @@ -454,8 +453,10 @@ int fscache_enable(size_t initial_size)
if (!initialized) {
if (!dwTlsIndex) {
dwTlsIndex = TlsAlloc();
if (dwTlsIndex == TLS_OUT_OF_INDEXES)
if (dwTlsIndex == TLS_OUT_OF_INDEXES) {
LeaveCriticalSection(&fscache_cs);
return 0;
}
}

/* redirect opendir and lstat to the fscache implementations */
Expand Down
2 changes: 1 addition & 1 deletion entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static int write_entry(struct cache_entry *ce,
if (!has_symlinks || to_tempfile)
goto write_file_entry;

ret = create_symlink(state ? state->istate : NULL, new_blob, path);
ret = create_symlink(state->istate, new_blob, path);
free(new_blob);
if (ret)
return error_errno("unable to create symlink %s", path);
Expand Down
3 changes: 2 additions & 1 deletion sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4884,7 +4884,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
struct object_id oid;
struct stat st;

get_oid(onto, &oid);
if (get_oid(onto, &oid) < 0)
return error(_("invalid rev: '%s'"), onto);
shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV);

if (!lstat(todo_file, &st) && st.st_size == 0 &&
Expand Down