aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 19:10:42 -0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 19:10:42 -0200
commitb27251f29dbf35b2580df0586779bc3366cf2dad (patch)
tree132c9a4a7880f64d3552a3481c77a9a9f0323f86
parent7127defbaa3701fc3444feb3233401e2829fc1b6 (diff)
downloadblogc-b27251f29dbf35b2580df0586779bc3366cf2dad.tar.gz
blogc-b27251f29dbf35b2580df0586779bc3366cf2dad.tar.bz2
blogc-b27251f29dbf35b2580df0586779bc3366cf2dad.zip
datetime-parser: fixed strptime error handling
-rw-r--r--src/datetime-parser.c7
-rw-r--r--tests/check_datetime_parser.c45
2 files changed, 49 insertions, 3 deletions
diff --git a/src/datetime-parser.c b/src/datetime-parser.c
index 1d39490..572c9f0 100644
--- a/src/datetime-parser.c
+++ b/src/datetime-parser.c
@@ -366,9 +366,10 @@ blogc_convert_datetime(const char *orig, const char *format,
char buf[1024];
if (0 == strftime(buf, sizeof(buf), format, &t)) {
- fprintf(stderr, "blogc: warning: Failed to format DATE variable, "
- "FORMAT is too long: %s\n", format);
- return b_strdup(orig);
+ *err = blogc_error_new_printf(BLOGC_ERROR_DATETIME_PARSER,
+ "Failed to format DATE variable, FORMAT is too long: %s",
+ format);
+ return NULL;
}
return b_strdup(buf);
diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c
index 37deb02..1997678 100644
--- a/tests/check_datetime_parser.c
+++ b/tests/check_datetime_parser.c
@@ -591,6 +591,50 @@ test_convert_datetime_invalid_seconds(void **state)
}
+static void
+test_convert_datetime_invalid_format_long(void **state)
+{
+ blogc_error_t *err = NULL;
+ char *dt = blogc_convert_datetime("2010-12-30 12:13:14",
+ "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
+ "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
+ "tywccrvnraagtnedwdjtfobinobbymanppwqxubxeepotdyxuvircyshpmtrqyvbivtycs"
+ "olwvqwdqaswdafohqkthraenpueuywbocrsbmmfoqwgbeixosyjljamcqwecfoxgolyxif"
+ "ltaoamuirnnsvoqcnboueqnnyksawwrdtcsiklanjxeavlaqsaswacmbvmselsnghiviet"
+ "wrftrfimjshrjlwxdhjkktivwmmesihlxkmqpmvfqjuimbmaucdxaqcgjdacgksqdseqko"
+ "prknyjylchdlijfgktveldlewixwrycytrjxxesrcbraydmbgitkldbxxhnjwqdmcwctat"
+ "rtjvrboulykkpvmsthontrunvkylwanwnnbpgwiwrgctfsvfgtxpifmpxhwikcylfeycjl"
+ "scmsjnvwfhlkwevcmvvoypmfqlnrwywkwvinkwbjpgxpdxfckghutcovrdhlatumhfvowb"
+ "fyiowyqpsbqhdxxauflpteyagsjtbulpktxmhkxxbgpetlwnckwsvhgmtasviemjeatejs"
+ "tslaivqeltycdgqylhqadxnrdlldbqdwuabdsrqwlxmetahvkrlvmyfgfftrlujfgktwve"
+ "vwidoqvigelfaohgjtaplygmmiwrcspaqntfhthikewunxhebqbkwiopplcmywvjeehslw"
+ "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq"
+ "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj"
+ "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err);
+ assert_null(dt);
+ assert_non_null(err);
+ assert_int_equal(err->type, BLOGC_ERROR_DATETIME_PARSER);
+ assert_string_equal(err->msg,
+ "Failed to format DATE variable, FORMAT is too long: "
+ "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
+ "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
+ "tywccrvnraagtnedwdjtfobinobbymanppwqxubxeepotdyxuvircyshpmtrqyvbivtycs"
+ "olwvqwdqaswdafohqkthraenpueuywbocrsbmmfoqwgbeixosyjljamcqwecfoxgolyxif"
+ "ltaoamuirnnsvoqcnboueqnnyksawwrdtcsiklanjxeavlaqsaswacmbvmselsnghiviet"
+ "wrftrfimjshrjlwxdhjkktivwmmesihlxkmqpmvfqjuimbmaucdxaqcgjdacgksqdseqko"
+ "prknyjylchdlijfgktveldlewixwrycytrjxxesrcbraydmbgitkldbxxhnjwqdmcwctat"
+ "rtjvrboulykkpvmsthontrunvkylwanwnnbpgwiwrgctfsvfgtxpifmpxhwikcylfeycjl"
+ "scmsjnvwfhlkwevcmvvoypmfqlnrwywkwvinkwbjpgxpdxfckghutcovrdhlatumhfvowb"
+ "fyiowyqpsbqhdxxauflpteyagsjtbulpktxmhkxxbgpetlwnckwsvhgmtasviemjeatejs"
+ "tslaivqeltycdgqylhqadxnrdlldbqdwuabdsrqwlxmetahvkrlvmyfgfftrlujfgktwve"
+ "vwidoqvigelfaohgjtaplygmmiwrcspaqntfhthikewunxhebqbkwiopplcmywvjeehslw"
+ "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq"
+ "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj"
+ "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg");
+ blogc_error_free(err);
+}
+
+
int
main(void)
{
@@ -626,6 +670,7 @@ main(void)
unit_test(test_convert_datetime_invalid_1st_seconds),
unit_test(test_convert_datetime_invalid_2nd_seconds),
unit_test(test_convert_datetime_invalid_seconds),
+ unit_test(test_convert_datetime_invalid_format_long),
};
return run_tests(tests);
}