caio.co/de/fuzzyclock

Fix crash when min = 58 or 59

Id
68668dee6a190dcc8c51ec5433729df72bb9333f
Author
Caio
Commit time
2012-03-28T11:24:46-03:00

Modified src/fuzzyclock.c

@@ -48,7 +48,7

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);

Modified tests/check_fuzzyclock.c

@@ -119,6 +119,11
}
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

// 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);