Fix crash when getting hour name of 0
- Id
- 4ed0c0292813478b69bc65f11f47b4a5e8267051
- Author
- Caio
- Commit time
- 2012-03-28T10:29:03-03:00
Modified src/fuzzyclock.c
};
char* const get_hour_string(int hour) {
+ if (hour < 1) hour = 12;
return HOUR_NAMES[(hour - 1) % 12];
}
Modified tests/check_fuzzyclock.c
}
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) {
tcase_add_test(tc_core, test_quarterto);
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);