Commit e572b631 by Edward Thomson Committed by GitHub

Merge pull request #4183 from pks-t/pks/coverity

Coverity
parents 44998cdb 9daba9f4
...@@ -517,11 +517,12 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt) ...@@ -517,11 +517,12 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
if (!num_parents) { if (!num_parents) {
git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit)); git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit));
goto finish; goto finish;
} } else if (num_parents < (int)ARRAY_SIZE(sg_buf))
else if (num_parents < (int)ARRAY_SIZE(sg_buf))
memset(sg_buf, 0, sizeof(sg_buf)); memset(sg_buf, 0, sizeof(sg_buf));
else else {
sg_origin = git__calloc(num_parents, sizeof(*sg_origin)); sg_origin = git__calloc(num_parents, sizeof(*sg_origin));
GITERR_CHECK_ALLOC(sg_origin);
}
for (i=0; i<num_parents; i++) { for (i=0; i<num_parents; i++) {
git_commit *p; git_commit *p;
......
...@@ -1027,7 +1027,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1027,7 +1027,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
first_quote = strchr(line, '"'); first_quote = strchr(line, '"');
if (first_quote == NULL) { if (first_quote == NULL) {
set_parse_error(reader, 0, "Missing quotation marks in section header"); set_parse_error(reader, 0, "Missing quotation marks in section header");
return -1; goto end_error;
} }
last_quote = strrchr(line, '"'); last_quote = strrchr(line, '"');
...@@ -1035,7 +1035,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1035,7 +1035,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
if (quoted_len == 0) { if (quoted_len == 0) {
set_parse_error(reader, 0, "Missing closing quotation mark in section header"); set_parse_error(reader, 0, "Missing closing quotation mark in section header");
return -1; goto end_error;
} }
GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len); GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
...@@ -1043,7 +1043,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1043,7 +1043,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
if (git_buf_grow(&buf, alloc_len) < 0 || if (git_buf_grow(&buf, alloc_len) < 0 ||
git_buf_printf(&buf, "%s.", base_name) < 0) git_buf_printf(&buf, "%s.", base_name) < 0)
goto end_parse; goto end_error;
rpos = 0; rpos = 0;
...@@ -1059,8 +1059,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1059,8 +1059,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
switch (c) { switch (c) {
case 0: case 0:
set_parse_error(reader, 0, "Unexpected end-of-line in section header"); set_parse_error(reader, 0, "Unexpected end-of-line in section header");
git_buf_free(&buf); goto end_error;
return -1;
case '"': case '"':
goto end_parse; goto end_parse;
...@@ -1070,8 +1069,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1070,8 +1069,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
if (c == 0) { if (c == 0) {
set_parse_error(reader, rpos, "Unexpected end-of-line in section header"); set_parse_error(reader, rpos, "Unexpected end-of-line in section header");
git_buf_free(&buf); goto end_error;
return -1;
} }
default: default:
...@@ -1083,10 +1081,8 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con ...@@ -1083,10 +1081,8 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
} while (line + rpos < last_quote); } while (line + rpos < last_quote);
end_parse: end_parse:
if (git_buf_oom(&buf)) { if (git_buf_oom(&buf))
git_buf_free(&buf); goto end_error;
return -1;
}
if (line[rpos] != '"' || line[rpos + 1] != ']') { if (line[rpos] != '"' || line[rpos + 1] != ']') {
set_parse_error(reader, rpos, "Unexpected text after closing quotes"); set_parse_error(reader, rpos, "Unexpected text after closing quotes");
...@@ -1096,6 +1092,11 @@ end_parse: ...@@ -1096,6 +1092,11 @@ end_parse:
*section_name = git_buf_detach(&buf); *section_name = git_buf_detach(&buf);
return 0; return 0;
end_error:
git_buf_free(&buf);
return -1;
} }
static int parse_section_header(struct reader *reader, char **section_out) static int parse_section_header(struct reader *reader, char **section_out)
......
...@@ -304,7 +304,9 @@ int git_futils_mmap_ro_file(git_map *out, const char *path) ...@@ -304,7 +304,9 @@ int git_futils_mmap_ro_file(git_map *out, const char *path)
if (fd < 0) if (fd < 0)
return fd; return fd;
len = git_futils_filesize(fd); if ((len = git_futils_filesize(fd)) < 0)
return -1;
if (!git__is_sizet(len)) { if (!git__is_sizet(len)) {
giterr_set(GITERR_OS, "file `%s` too large to mmap", path); giterr_set(GITERR_OS, "file `%s` too large to mmap", path);
return -1; return -1;
......
...@@ -700,7 +700,8 @@ static bool _check_dir_contents( ...@@ -700,7 +700,8 @@ static bool _check_dir_contents(
return false; return false;
/* save excursion */ /* save excursion */
git_buf_joinpath(dir, dir->ptr, sub); if (git_buf_joinpath(dir, dir->ptr, sub) < 0)
return false;
result = predicate(dir->ptr); result = predicate(dir->ptr);
...@@ -825,8 +826,8 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling) ...@@ -825,8 +826,8 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
int git_path_apply_relative(git_buf *target, const char *relpath) int git_path_apply_relative(git_buf *target, const char *relpath)
{ {
git_buf_joinpath(target, git_buf_cstr(target), relpath); return git_buf_joinpath(target, git_buf_cstr(target), relpath) ||
return git_path_resolve_relative(target, 0); git_path_resolve_relative(target, 0);
} }
int git_path_cmp( int git_path_cmp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment