Skip to content
Browse files

Fix crash when min = 58 or 59

  • Loading branch information...
1 parent c54634b commit 68668dee6a190dcc8c51ec5433729df72bb9333f @caio committed
Showing with 7 additions and 1 deletion.
  1. +1 −1 src/fuzzyclock.c
  2. +6 −0 tests/check_fuzzyclock.c
View
2 src/fuzzyclock.c
@@ -48,7 +48,7 @@ void get_fuzzy_time(struct tm* clock, char* buffer) {
if (index > 6) { hour++; }
- char* timestr = FUZZY_MSG[index];
+ char* timestr = FUZZY_MSG[index % 12];
char* hourname = get_hour_string(hour);
snprintf(buffer, MAX_MSG_SIZE, timestr, hourname);
View
6 tests/check_fuzzyclock.c
@@ -119,6 +119,11 @@ START_TEST(test_fiveto) {
}
END_TEST
+START_TEST(test_58_59_should_be_oclock) {
+ fuzzy_time_test_gen(1, 58, 58, 60, "%s o' clock", 0);
+}
+END_TEST
+
Suite* fuzzy_suite(void) {
Suite* suite = suite_create("fuzzyclock");
@@ -142,6 +147,7 @@ Suite* fuzzy_suite(void) {
// corner cases
tcase_add_test(tc_core, test_zero_should_be_twelve);
+ tcase_add_test(tc_core, test_58_59_should_be_oclock);
suite_add_tcase(suite, tc_core);

0 comments on commit 68668de

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