Skip to content

Commit a44dad8

Browse files
committed
Merge branch 'coverity-fixes-unchecked-returns' into HEAD
2 parents 18003a8 + 1ea1e0e commit a44dad8

10 files changed

Lines changed: 47 additions & 12 deletions

File tree

bisect.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,12 @@ void read_bisect_terms(char **read_bad, char **read_good)
10191019
die_errno(_("could not read file '%s'"), filename);
10201020
}
10211021
} else {
1022-
strbuf_getline_lf(&str, fp);
1022+
if (strbuf_getline_lf(&str, fp) == EOF)
1023+
die(_("could not read bad term from file '%s'"), filename);
10231024
free(*read_bad);
10241025
*read_bad = strbuf_detach(&str, NULL);
1025-
strbuf_getline_lf(&str, fp);
1026+
if (strbuf_getline_lf(&str, fp) == EOF)
1027+
die(_("could not read good term from file '%s'"), filename);
10261028
free(*read_good);
10271029
*read_good = strbuf_detach(&str, NULL);
10281030
}

builtin/bisect.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,15 @@ static int get_terms(struct bisect_terms *terms)
495495
}
496496

497497
free_terms(terms);
498-
strbuf_getline_lf(&str, fp);
498+
if (strbuf_getline_lf(&str, fp) == EOF) {
499+
res = -1;
500+
goto finish;
501+
}
499502
terms->term_bad = strbuf_detach(&str, NULL);
500-
strbuf_getline_lf(&str, fp);
503+
if (strbuf_getline_lf(&str, fp) == EOF) {
504+
res = -1;
505+
goto finish;
506+
}
501507
terms->term_good = strbuf_detach(&str, NULL);
502508

503509
finish:
@@ -1055,6 +1061,8 @@ static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
10551061
*word_end = '\0'; /* NUL-terminate the word */
10561062

10571063
get_terms(terms);
1064+
if (!terms->term_bad || !terms->term_good)
1065+
return error(_("no terms defined"));
10581066
if (check_and_set_terms(terms, p))
10591067
return -1;
10601068

@@ -1381,6 +1389,8 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13811389
return error(_("'%s' requires 0 arguments"),
13821390
"git bisect next");
13831391
get_terms(&terms);
1392+
if (!terms.term_bad || !terms.term_good)
1393+
return error(_("no terms defined"));
13841394
res = bisect_next(&terms, prefix);
13851395
free_terms(&terms);
13861396
return res;
@@ -1415,6 +1425,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
14151425

14161426
set_terms(&terms, "bad", "good");
14171427
get_terms(&terms);
1428+
if (!terms.term_bad || !terms.term_good)
1429+
return error(_("no terms defined"));
14181430
res = bisect_skip(&terms, argc, argv);
14191431
free_terms(&terms);
14201432
return res;
@@ -1427,6 +1439,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
14271439
struct bisect_terms terms = { 0 };
14281440

14291441
get_terms(&terms);
1442+
if (!terms.term_bad || !terms.term_good)
1443+
return error(_("no terms defined"));
14301444
res = bisect_visualize(&terms, argc, argv);
14311445
free_terms(&terms);
14321446
return res;
@@ -1441,6 +1455,8 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
14411455
if (!argc)
14421456
return error(_("'%s' failed: no command provided."), "git bisect run");
14431457
get_terms(&terms);
1458+
if (!terms.term_bad || !terms.term_good)
1459+
return error(_("no terms defined"));
14441460
res = bisect_run(&terms, argc, argv);
14451461
free_terms(&terms);
14461462
return res;
@@ -1480,6 +1496,8 @@ int cmd_bisect(int argc,
14801496

14811497
set_terms(&terms, "bad", "good");
14821498
get_terms(&terms);
1499+
if (!terms.term_bad || !terms.term_good)
1500+
return error(_("no terms defined"));
14831501
if (check_and_set_terms(&terms, argv[0]) ||
14841502
!one_of(argv[0], terms.term_good, terms.term_bad, NULL))
14851503
usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,

builtin/config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,10 @@ static int show_editor(struct config_location_options *opts)
12901290
else if (errno != EEXIST)
12911291
die_errno(_("cannot create configuration file %s"), config_file);
12921292
}
1293-
launch_editor(config_file, NULL, NULL);
1293+
if (launch_editor(config_file, NULL, NULL)) {
1294+
free(config_file);
1295+
return -1;
1296+
}
12941297
free(config_file);
12951298

12961299
return 0;

builtin/last-modified.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ static void process_parent(struct last_modified *lm,
290290
{
291291
struct bitmap *active_p;
292292

293-
repo_parse_commit(lm->rev.repo, parent);
293+
if (repo_parse_commit(lm->rev.repo, parent))
294+
return;
294295
active_p = active_paths_for(lm, parent);
295296

296297
/*
@@ -414,13 +415,15 @@ static int last_modified_run(struct last_modified *lm)
414415
* Otherwise, make sure that 'c' isn't reachable from anything
415416
* in the '--not' queue.
416417
*/
417-
repo_parse_commit(lm->rev.repo, c);
418+
if (repo_parse_commit(lm->rev.repo, c))
419+
continue;
418420

419421
while (not_queue.nr) {
420422
struct commit_list *np;
421423
struct commit *n = prio_queue_get(&not_queue);
422424

423-
repo_parse_commit(lm->rev.repo, n);
425+
if (repo_parse_commit(lm->rev.repo, n))
426+
continue;
424427

425428
for (np = n->parents; np; np = np->next) {
426429
if (!(np->item->object.flags & PARENT2)) {

builtin/pack-redundant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static void scan_alt_odb_packs(void)
536536

537537
static struct pack_list * add_pack(struct packed_git *p)
538538
{
539-
struct pack_list l;
539+
struct pack_list l = { NULL };
540540
size_t off = 0, step;
541541
const unsigned char *base;
542542

compat/pread.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ssize_t git_pread(int fd, void *buf, size_t count, off_t offset)
77
ssize_t rc;
88

99
current_offset = lseek(fd, 0, SEEK_CUR);
10+
if (current_offset < 0)
11+
return -1;
1012

1113
if (lseek(fd, offset, SEEK_SET) < 0)
1214
return -1;

http.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,8 @@ struct active_request_slot *get_active_slot(void)
16151615

16161616
if (!slot->curl) {
16171617
slot->curl = curl_easy_duphandle(curl_default);
1618+
if (!slot->curl)
1619+
die("curl_easy_duphandle failed");
16181620
curl_session_count++;
16191621
}
16201622

reftable/block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ int block_writer_init(struct block_writer *bw, uint8_t typ, uint8_t *block,
8787
REFTABLE_CALLOC_ARRAY(bw->zstream, 1);
8888
if (!bw->zstream)
8989
return REFTABLE_OUT_OF_MEMORY_ERROR;
90-
deflateInit(bw->zstream, 9);
90+
if (deflateInit(bw->zstream, 9) != Z_OK)
91+
return REFTABLE_ZLIB_ERROR;
9192
}
9293

9394
return 0;

t/unit-tests/u-reftable-table.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ void test_reftable_table__seek_once(void)
2828
ret = reftable_table_new(&table, &source, "name");
2929
cl_assert(!ret);
3030

31-
reftable_table_init_ref_iterator(table, &it);
31+
ret = reftable_table_init_ref_iterator(table, &it);
32+
cl_assert_equal_i(ret, 0);
3233
ret = reftable_iterator_seek_ref(&it, "");
3334
cl_assert(!ret);
3435
ret = reftable_iterator_next_ref(&it, &ref);
@@ -70,7 +71,8 @@ void test_reftable_table__reseek(void)
7071
ret = reftable_table_new(&table, &source, "name");
7172
cl_assert(!ret);
7273

73-
reftable_table_init_ref_iterator(table, &it);
74+
ret = reftable_table_init_ref_iterator(table, &it);
75+
cl_assert_equal_i(ret, 0);
7476

7577
for (size_t i = 0; i < 5; i++) {
7678
ret = reftable_iterator_seek_ref(&it, "");

transport-helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ static int get_exporter(struct transport *transport,
491491
/* we need to duplicate helper->in because we want to use it after
492492
* fastexport is done with it. */
493493
fastexport->out = dup(helper->in);
494+
if (fastexport->out < 0)
495+
return error_errno(_("could not dup helper output fd"));
494496
strvec_push(&fastexport->args, "fast-export");
495497
strvec_push(&fastexport->args, "--use-done-feature");
496498
strvec_push(&fastexport->args, data->signed_tags ?

0 commit comments

Comments
 (0)