Skip to content

Commit 5068350

Browse files
committed
feat: update counter logic and fuzz tests
1 parent aba9352 commit 5068350

4 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/ascii_counter.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ int ascii_validate_token(char h_symbol, char l_symbol, int* cnt)
116116
if(ASCII_IS_ALPHA(l_symbol) || l_symbol == '0')
117117
return ASCII_ERROR;
118118

119-
if (ASCII_IS_NUMERIC(h_symbol) && ASCII_IS_NUMERIC(l_symbol))
120-
return ASCII_ERROR;
121-
122-
if (ASCII_IS_ALPHA(h_symbol) && ASCII_IS_ALPHA(l_symbol))
123-
return ASCII_ERROR;
124-
125-
if (ASCII_IS_NUMERIC(h_symbol) && ASCII_IS_ALPHA(l_symbol))
126-
return ASCII_ERROR;
127-
128119
return ASCII_OK;
129120
}
130121

src/ascii_counter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define ASCII_ERROR_MISS_DELIMETR -5
1616
#define ASCII_ERROR_MAX_SIZE -6
1717

18-
#define ASCII_MAX_SIZE 10*2
18+
#define ASCII_MAX_SIZE (10*2)
1919

2020
#define ASCII_IS_DELIMITER(_x) (_x == '-')
2121
#define ASCII_IS_NUMERIC(_x) (_x >= '0' && _x <= '9')

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(TESTS
22
error_sequence
3-
good_sequence)
3+
good_sequence
4+
fuzz_sequence)
45

56
foreach(fname ${TESTS})
67
add_executable(test_${fname} test_${fname}.c)

tests/test_fuzz_sequence.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,50 @@ MU_TEST(test_fuzz_data) {
1212
mu_check(buff == NULL);
1313
}
1414

15+
MU_TEST(test_fuzz_boundary) {
16+
17+
buff = ascii_parse("A1", &rc);
18+
mu_check(rc < 0);
19+
mu_check(buff == NULL);
20+
21+
buff = ascii_parse("B0", &rc);
22+
mu_check(rc < 0);
23+
mu_check(buff == NULL);
24+
25+
buff = ascii_parse("-B1", &rc);
26+
mu_check(rc < 0);
27+
mu_check(buff == NULL);
28+
29+
buff = ascii_parse("B1-", &rc);
30+
mu_check(rc < 0);
31+
mu_check(buff == NULL);
32+
33+
buff = ascii_parse("ZZ", &rc);
34+
mu_check(rc < 0);
35+
mu_check(buff == NULL);
36+
37+
buff = ascii_parse("11", &rc);
38+
mu_check(rc < 0);
39+
mu_check(buff == NULL);
40+
}
41+
42+
MU_TEST(test_fuzz_overflow) {
43+
44+
buff = ascii_parse("B1-B1-B1-B1-B1-B1-B1-B1-B1-B1-B1", &rc);
45+
mu_check(rc < 0);
46+
mu_check(buff == NULL);
47+
48+
buff = ascii_parse("F1G", &rc);
49+
mu_check(rc < 0);
50+
mu_check(buff == NULL);
51+
}
52+
1553

1654
int main()
1755
{
1856
MU_RUN_TEST(test_fuzz_data);
57+
MU_RUN_TEST(test_fuzz_boundary);
58+
MU_RUN_TEST(test_fuzz_overflow);
1959
MU_REPORT();
2060
return MU_EXIT_CODE;
21-
}
61+
}

0 commit comments

Comments
 (0)