Skip to content
Browse files

Fix crash when getting hour name of 0

  • Loading branch information...
1 parent 7f2e4a3 commit 4ed0c0292813478b69bc65f11f47b4a5e8267051 @caio committed
Showing with 9 additions and 0 deletions.
  1. +1 −0 src/fuzzyclock.c
  2. +8 −0 tests/check_fuzzyclock.c
View
1 src/fuzzyclock.c
@@ -33,6 +33,7 @@ char* FUZZY_MSG[] = {
};
char* const get_hour_string(int hour) {
+ if (hour < 1) hour = 12;
return HOUR_NAMES[(hour - 1) % 12];
}
View
8 tests/check_fuzzyclock.c
@@ -20,6 +20,11 @@ START_TEST(test_get_hour_string) {
}
END_TEST
+START_TEST(test_zero_should_be_twelve) {
+ fail_if(strcmp(get_hour_string(0), "twelve") != 0, NULL);
+}
+END_TEST
+
void fuzzy_time_test_gen(int hour, int min, int start, int end,
char* expect_mask, int iter_on_hour) {
@@ -135,6 +140,9 @@ Suite* fuzzy_suite(void) {
tcase_add_test(tc_core, test_tento);
tcase_add_test(tc_core, test_fiveto);
+ // corner cases
+ tcase_add_test(tc_core, test_zero_should_be_twelve);
+
suite_add_tcase(suite, tc_core);
return suite;

0 comments on commit 4ed0c02

Please sign in to comment.
Something went wrong with that request. Please try again.