Skip to content

Commit f8cc52b

Browse files
committed
Merge branch 'ua/t3404-cleanup' into jch
Test update. * ua/t3404-cleanup: parse: replace atoi() with strtoul_ui() and strtol_i() t3404: replace test with test_line_count() t3404: avoid losing exit status with focus on `git show` and `git cat-file`
2 parents 84f5925 + 40cd9d8 commit f8cc52b

File tree

4 files changed

+69
-39
lines changed

4 files changed

+69
-39
lines changed

daemon.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,17 +1308,21 @@ int cmd_main(int argc, const char **argv)
13081308
continue;
13091309
}
13101310
if (skip_prefix(arg, "--timeout=", &v)) {
1311-
timeout = atoi(v);
1311+
if (strtoul_ui(v, 10, &timeout) < 0) {
1312+
die("'%s': not a valid integer for --timeout", v);
1313+
}
13121314
continue;
13131315
}
13141316
if (skip_prefix(arg, "--init-timeout=", &v)) {
1315-
init_timeout = atoi(v);
1317+
if (strtoul_ui(v, 10, &init_timeout) < 0) {
1318+
die("'%s': not a valid integer for --init-timeout", v);
1319+
}
13161320
continue;
13171321
}
13181322
if (skip_prefix(arg, "--max-connections=", &v)) {
1319-
max_connections = atoi(v);
1320-
if (max_connections < 0)
1321-
max_connections = 0; /* unlimited */
1323+
if (strtol_i(v, 10, &max_connections) != 0 || max_connections < 0) {
1324+
max_connections = 0; /* unlimited */
1325+
}
13221326
continue;
13231327
}
13241328
if (!strcmp(arg, "--strict-paths")) {

imap-send.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
668668
return RESP_BAD;
669669
}
670670
if (!strcmp("UIDVALIDITY", arg)) {
671-
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
671+
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) != 0) {
672672
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
673673
return RESP_BAD;
674674
}
675675
} else if (!strcmp("UIDNEXT", arg)) {
676-
if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) {
676+
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) != 0) {
677677
fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
678678
return RESP_BAD;
679679
}
@@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
686686
for (; isspace((unsigned char)*p); p++);
687687
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
688688
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
689-
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||
690-
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
689+
if (!(arg = next_arg(&s)) || (strtol_i(arg, 10, &ctx->uidvalidity) != 0) ||
690+
!(arg = next_arg(&s)) || (strtol_i(arg, 10, (int *)cb->ctx) != 0)) {
691691
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
692692
return RESP_BAD;
693693
}
@@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
773773
if (!tcmd)
774774
return DRV_OK;
775775
} else {
776-
tag = atoi(arg);
776+
if (strtol_i(arg, 10, &tag) != 0) {
777+
fprintf(stderr, "IMAP error: malformed tag %s\n", arg);
778+
return RESP_BAD;
779+
}
777780
for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
778781
if (cmdp->tag == tag)
779782
goto gottag;

merge-ll.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
427427
git_check_attr(istate, path, check);
428428
ll_driver_name = check->items[0].value;
429429
if (check->items[1].value) {
430-
marker_size = atoi(check->items[1].value);
431-
if (marker_size <= 0)
430+
if (strtol_i(check->items[1].value, 10, &marker_size) != 0 || marker_size <= 0)
432431
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
433432
}
434433
driver = find_ll_merge_driver(ll_driver_name);
@@ -454,8 +453,7 @@ int ll_merge_marker_size(struct index_state *istate, const char *path)
454453
check = attr_check_initl("conflict-marker-size", NULL);
455454
git_check_attr(istate, path, check);
456455
if (check->items[0].value) {
457-
marker_size = atoi(check->items[0].value);
458-
if (marker_size <= 0)
456+
if (strtol_i(check->items[0].value, 10, &marker_size) != 0 || marker_size <= 0)
459457
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
460458
}
461459
return marker_size;

t/t3404-rebase-interactive.sh

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ test_expect_success 'stop on conflicting pick' '
281281
test_cmp expect2 file1 &&
282282
test "$(git diff --name-status |
283283
sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
284-
test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
285-
test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
284+
grep -v "^#" <.git/rebase-merge/done >actual &&
285+
test_line_count = 4 actual &&
286+
test 0 = $(grep -c "^[^#]" <.git/rebase-merge/git-rebase-todo)
286287
'
287288

288289
test_expect_success 'show conflicted patch' '
@@ -319,7 +320,8 @@ test_expect_success 'retain authorship' '
319320
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
320321
git tag twerp &&
321322
git rebase -i --onto primary HEAD^ &&
322-
git show HEAD | grep "^Author: Twerp Snog"
323+
git show HEAD >actual &&
324+
grep "^Author: Twerp Snog" actual
323325
'
324326

325327
test_expect_success 'retain authorship w/ conflicts' '
@@ -360,7 +362,8 @@ test_expect_success 'squash' '
360362
'
361363

362364
test_expect_success 'retain authorship when squashing' '
363-
git show HEAD | grep "^Author: Twerp Snog"
365+
git show HEAD >actual &&
366+
grep "^Author: Twerp Snog" actual
364367
'
365368

366369
test_expect_success '--continue tries to commit' '
@@ -374,7 +377,8 @@ test_expect_success '--continue tries to commit' '
374377
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
375378
) &&
376379
test_cmp_rev HEAD^ new-branch1 &&
377-
git show HEAD | grep chouette
380+
git show HEAD >actual &&
381+
grep chouette actual
378382
'
379383

380384
test_expect_success 'verbose flag is heeded, even after --continue' '
@@ -397,7 +401,9 @@ test_expect_success 'multi-squash only fires up editor once' '
397401
git rebase -i $base
398402
) &&
399403
test $base = $(git rev-parse HEAD^) &&
400-
test 1 = $(git show | grep ONCE | wc -l)
404+
git show >output &&
405+
grep ONCE output >actual &&
406+
test_line_count = 1 actual
401407
'
402408

403409
test_expect_success 'multi-fixup does not fire up editor' '
@@ -410,7 +416,8 @@ test_expect_success 'multi-fixup does not fire up editor' '
410416
git rebase -i $base
411417
) &&
412418
test $base = $(git rev-parse HEAD^) &&
413-
test 0 = $(git show | grep NEVER | wc -l) &&
419+
git show >output &&
420+
! grep NEVER output &&
414421
git checkout @{-1} &&
415422
git branch -D multi-fixup
416423
'
@@ -428,7 +435,9 @@ test_expect_success 'commit message used after conflict' '
428435
git rebase --continue
429436
) &&
430437
test $base = $(git rev-parse HEAD^) &&
431-
test 1 = $(git show | grep ONCE | wc -l) &&
438+
git show >output &&
439+
grep ONCE output >actual &&
440+
test_line_count = 1 actual &&
432441
git checkout @{-1} &&
433442
git branch -D conflict-fixup
434443
'
@@ -446,7 +455,9 @@ test_expect_success 'commit message retained after conflict' '
446455
git rebase --continue
447456
) &&
448457
test $base = $(git rev-parse HEAD^) &&
449-
test 2 = $(git show | grep TWICE | wc -l) &&
458+
git show >output &&
459+
grep TWICE output >actual &&
460+
test_line_count = 2 actual &&
450461
git checkout @{-1} &&
451462
git branch -D conflict-squash
452463
'
@@ -470,10 +481,10 @@ test_expect_success 'squash and fixup generate correct log messages' '
470481
) &&
471482
git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
472483
test_cmp expect-squash-fixup actual-squash-fixup &&
473-
git cat-file commit HEAD@{2} |
474-
grep "^# This is a combination of 3 commits\." &&
475-
git cat-file commit HEAD@{3} |
476-
grep "^# This is a combination of 2 commits\." &&
484+
git cat-file commit HEAD@{2} >actual &&
485+
grep "^# This is a combination of 3 commits\." actual &&
486+
git cat-file commit HEAD@{3} >actual &&
487+
grep "^# This is a combination of 2 commits\." actual &&
477488
git checkout @{-1} &&
478489
git branch -D squash-fixup
479490
'
@@ -489,7 +500,9 @@ test_expect_success 'squash ignores comments' '
489500
git rebase -i $base
490501
) &&
491502
test $base = $(git rev-parse HEAD^) &&
492-
test 1 = $(git show | grep ONCE | wc -l) &&
503+
git show >output &&
504+
grep ONCE output >actual &&
505+
test_line_count = 1 actual &&
493506
git checkout @{-1} &&
494507
git branch -D skip-comments
495508
'
@@ -505,7 +518,9 @@ test_expect_success 'squash ignores blank lines' '
505518
git rebase -i $base
506519
) &&
507520
test $base = $(git rev-parse HEAD^) &&
508-
test 1 = $(git show | grep ONCE | wc -l) &&
521+
git show >output &&
522+
grep ONCE output >actual &&
523+
test_line_count = 1 actual &&
509524
git checkout @{-1} &&
510525
git branch -D skip-blank-lines
511526
'
@@ -572,7 +587,8 @@ test_expect_success '--continue tries to commit, even for "edit"' '
572587
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
573588
) &&
574589
test edited = $(git show HEAD:file7) &&
575-
git show HEAD | grep chouette &&
590+
git show HEAD >actual &&
591+
grep chouette actual &&
576592
test $parent = $(git rev-parse HEAD^)
577593
'
578594

@@ -757,19 +773,23 @@ test_expect_success 'reword' '
757773
set_fake_editor &&
758774
FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
759775
git rebase -i A &&
760-
git show HEAD | grep "E changed" &&
776+
git show HEAD >actual &&
777+
grep "E changed" actual &&
761778
test $(git rev-parse primary) != $(git rev-parse HEAD) &&
762779
test_cmp_rev primary^ HEAD^ &&
763780
FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
764781
git rebase -i A &&
765-
git show HEAD^ | grep "D changed" &&
782+
git show HEAD^ >actual &&
783+
grep "D changed" actual &&
766784
FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
767785
git rebase -i A &&
768-
git show HEAD~3 | grep "B changed" &&
786+
git show HEAD~3 >actual &&
787+
grep "B changed" actual &&
769788
FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
770789
git rebase -i A
771790
) &&
772-
git show HEAD~2 | grep "C changed"
791+
git show HEAD~2 >actual &&
792+
grep "C changed" actual
773793
'
774794

775795
test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' '
@@ -1003,8 +1023,10 @@ test_expect_success 'rebase -i --root retain root commit author and message' '
10031023
set_fake_editor &&
10041024
FAKE_LINES="2" git rebase -i --root
10051025
) &&
1006-
git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1007-
git cat-file commit HEAD | grep -q "^different author$"
1026+
git cat-file commit HEAD >output &&
1027+
grep -q "^author Twerp Snog" output &&
1028+
git cat-file commit HEAD >actual &&
1029+
grep -q "^different author$" actual
10081030
'
10091031

10101032
test_expect_success 'rebase -i --root temporary sentinel commit' '
@@ -1013,7 +1035,8 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
10131035
set_fake_editor &&
10141036
test_must_fail env FAKE_LINES="2" git rebase -i --root
10151037
) &&
1016-
git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1038+
git cat-file commit HEAD >actual &&
1039+
grep "^tree $EMPTY_TREE" actual &&
10171040
git rebase --abort
10181041
'
10191042

@@ -1036,7 +1059,8 @@ test_expect_success 'rebase -i --root reword original root commit' '
10361059
FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
10371060
git rebase -i --root
10381061
) &&
1039-
git show HEAD^ | grep "A changed" &&
1062+
git show HEAD^ >actual &&
1063+
grep "A changed" actual &&
10401064
test -z "$(git show -s --format=%p HEAD^)"
10411065
'
10421066

@@ -1048,7 +1072,8 @@ test_expect_success 'rebase -i --root reword new root commit' '
10481072
FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
10491073
git rebase -i --root
10501074
) &&
1051-
git show HEAD^ | grep "C changed" &&
1075+
git show HEAD^ >actual &&
1076+
grep "C changed" actual &&
10521077
test -z "$(git show -s --format=%p HEAD^)"
10531078
'
10541079

0 commit comments

Comments
 (0)