Skip to content

Commit e572b63

Browse files
authored
Merge pull request libgit2#4183 from pks-t/pks/coverity
Coverity
2 parents 44998cd + 9daba9f commit e572b63

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/blame_git.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,12 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
517517
if (!num_parents) {
518518
git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit));
519519
goto finish;
520-
}
521-
else if (num_parents < (int)ARRAY_SIZE(sg_buf))
520+
} else if (num_parents < (int)ARRAY_SIZE(sg_buf))
522521
memset(sg_buf, 0, sizeof(sg_buf));
523-
else
522+
else {
524523
sg_origin = git__calloc(num_parents, sizeof(*sg_origin));
524+
GITERR_CHECK_ALLOC(sg_origin);
525+
}
525526

526527
for (i=0; i<num_parents; i++) {
527528
git_commit *p;

src/config_file.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,23 +1027,23 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10271027
first_quote = strchr(line, '"');
10281028
if (first_quote == NULL) {
10291029
set_parse_error(reader, 0, "Missing quotation marks in section header");
1030-
return -1;
1030+
goto end_error;
10311031
}
10321032

10331033
last_quote = strrchr(line, '"');
10341034
quoted_len = last_quote - first_quote;
10351035

10361036
if (quoted_len == 0) {
10371037
set_parse_error(reader, 0, "Missing closing quotation mark in section header");
1038-
return -1;
1038+
goto end_error;
10391039
}
10401040

10411041
GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
10421042
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
10431043

10441044
if (git_buf_grow(&buf, alloc_len) < 0 ||
10451045
git_buf_printf(&buf, "%s.", base_name) < 0)
1046-
goto end_parse;
1046+
goto end_error;
10471047

10481048
rpos = 0;
10491049

@@ -1059,8 +1059,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10591059
switch (c) {
10601060
case 0:
10611061
set_parse_error(reader, 0, "Unexpected end-of-line in section header");
1062-
git_buf_free(&buf);
1063-
return -1;
1062+
goto end_error;
10641063

10651064
case '"':
10661065
goto end_parse;
@@ -1070,8 +1069,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10701069

10711070
if (c == 0) {
10721071
set_parse_error(reader, rpos, "Unexpected end-of-line in section header");
1073-
git_buf_free(&buf);
1074-
return -1;
1072+
goto end_error;
10751073
}
10761074

10771075
default:
@@ -1083,10 +1081,8 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10831081
} while (line + rpos < last_quote);
10841082

10851083
end_parse:
1086-
if (git_buf_oom(&buf)) {
1087-
git_buf_free(&buf);
1088-
return -1;
1089-
}
1084+
if (git_buf_oom(&buf))
1085+
goto end_error;
10901086

10911087
if (line[rpos] != '"' || line[rpos + 1] != ']') {
10921088
set_parse_error(reader, rpos, "Unexpected text after closing quotes");
@@ -1096,6 +1092,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10961092

10971093
*section_name = git_buf_detach(&buf);
10981094
return 0;
1095+
1096+
end_error:
1097+
git_buf_free(&buf);
1098+
1099+
return -1;
10991100
}
11001101

11011102
static int parse_section_header(struct reader *reader, char **section_out)

src/fileops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ int git_futils_mmap_ro_file(git_map *out, const char *path)
304304
if (fd < 0)
305305
return fd;
306306

307-
len = git_futils_filesize(fd);
307+
if ((len = git_futils_filesize(fd)) < 0)
308+
return -1;
309+
308310
if (!git__is_sizet(len)) {
309311
giterr_set(GITERR_OS, "file `%s` too large to mmap", path);
310312
return -1;

src/path.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ static bool _check_dir_contents(
700700
return false;
701701

702702
/* save excursion */
703-
git_buf_joinpath(dir, dir->ptr, sub);
703+
if (git_buf_joinpath(dir, dir->ptr, sub) < 0)
704+
return false;
704705

705706
result = predicate(dir->ptr);
706707

@@ -825,8 +826,8 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
825826

826827
int git_path_apply_relative(git_buf *target, const char *relpath)
827828
{
828-
git_buf_joinpath(target, git_buf_cstr(target), relpath);
829-
return git_path_resolve_relative(target, 0);
829+
return git_buf_joinpath(target, git_buf_cstr(target), relpath) ||
830+
git_path_resolve_relative(target, 0);
830831
}
831832

832833
int git_path_cmp(

0 commit comments

Comments
 (0)