Skip to content

Commit 63297e8

Browse files
alejandro-colomarhallyn
authored andcommitted
lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base
Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 745281f commit 63297e8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/atoi/strtoi/strtoi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ strtoi_(const char *s, char **restrict endp, int base,
3636
if (status == NULL)
3737
status = &st;
3838

39-
if (base != 0 && (base < 0 || base > 36)) {
39+
if (base != 0 && (base < 2 || base > 36)) {
4040
*status = EINVAL;
4141
return MAX(min, MIN(max, 0));
4242
}

lib/atoi/strtoi/strtou.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ strtou_(const char *s, char **restrict endp, int base,
3636
if (status == NULL)
3737
status = &st;
3838

39-
if (base != 0 && (base < 0 || base > 36)) {
39+
if (base != 0 && (base < 2 || base > 36)) {
4040
*status = EINVAL;
4141
return MAX(min, 0);
4242
}

tests/unit/test_atoi_strtoi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ test_strtoi(void **state)
4646
assert_true(strtoi_("42", NULL, -1, 1, 2, &status) == 1);
4747
assert_true(status == EINVAL);
4848

49+
assert_true(strtoi_("42", NULL, 1, 1, 2, &status) == 1);
50+
assert_true(status == EINVAL);
51+
4952
assert_true(strtoi_("40", &end, 5, INTMAX_MIN, INTMAX_MAX, &status) == 20);
5053
assert_true(status == 0);
5154
assert_true(strcmp(end, "") == 0);
@@ -84,6 +87,9 @@ test_strtou(void **state)
8487
assert_true(strtou_("42", NULL, -1, 1, 2, &status) == 1);
8588
assert_true(status == EINVAL);
8689

90+
assert_true(strtou_("42", NULL, 1, 1, 2, &status) == 1);
91+
assert_true(status == EINVAL);
92+
8793
assert_true(strtou_("40", &end, 5, 0, UINTMAX_MAX, &status) == 20);
8894
assert_true(status == 0);
8995
assert_true(strcmp(end, "") == 0);
@@ -123,6 +129,10 @@ test_strtou_noneg(void **state)
123129
== 1);
124130
assert_true(status == EINVAL);
125131

132+
assert_true(strtou_noneg("42", NULL, 1, 1, 2, &status)
133+
== 1);
134+
assert_true(status == EINVAL);
135+
126136
assert_true(strtou_noneg("40", &end, 5, 0, UINTMAX_MAX, &status)
127137
== 20);
128138
assert_true(status == 0);

0 commit comments

Comments
 (0)