examples: Check whether the returned date is valid

Prints may have an invalid date. Extend the checks so that this is also
caught in addition to a NULL date.
This commit is contained in:
Benjamin Berg
2022-01-28 17:30:37 +01:00
parent ae5696a9bb
commit 168ab98021
3 changed files with 9 additions and 5 deletions

View File

@@ -143,6 +143,7 @@ on_identify_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
if (match) if (match)
{ {
g_autoptr(FpPrint) matched_print = g_object_ref (match); g_autoptr(FpPrint) matched_print = g_object_ref (match);
const GDate *date;
char date_str[128] = {}; char date_str[128] = {};
identify_data->ret_value = EXIT_SUCCESS; identify_data->ret_value = EXIT_SUCCESS;
@@ -155,7 +156,8 @@ on_identify_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
matched_print = g_steal_pointer (&stored_print); matched_print = g_steal_pointer (&stored_print);
} }
if (fp_print_get_enroll_date (matched_print)) date = fp_print_get_enroll_date (matched_print);
if (date && g_date_valid (date))
g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0", g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0",
fp_print_get_enroll_date (matched_print)); fp_print_get_enroll_date (matched_print));
else else

View File

@@ -161,7 +161,7 @@ on_list_completed (FpDevice *dev,
finger_to_string (fp_print_get_finger (print)), finger_to_string (fp_print_get_finger (print)),
fp_print_get_username (print)); fp_print_get_username (print));
if (date) if (date && g_date_valid (date))
{ {
g_date_strftime (buf, G_N_ELEMENTS (buf), "%Y-%m-%d\0", date); g_date_strftime (buf, G_N_ELEMENTS (buf), "%Y-%m-%d\0", date);
g_print (", enrolled on %s", buf); g_print (", enrolled on %s", buf);

View File

@@ -130,10 +130,12 @@ on_match_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
if (match) if (match)
{ {
char date_str[128]; const GDate *date = fp_print_get_enroll_date (match);
char date_str[128] = "<unknown>";
verify_data->ret_value = EXIT_SUCCESS; verify_data->ret_value = EXIT_SUCCESS;
if (date && g_date_valid (date))
g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0", g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0",
fp_print_get_enroll_date (match)); fp_print_get_enroll_date (match));
g_debug ("Match report: device %s matched finger %s successifully " g_debug ("Match report: device %s matched finger %s successifully "