diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-01-28 17:30:37 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2022-02-03 14:49:49 +0100 |
commit | 168ab980219a3265b0f70e6f19edd65e6d9fc59c (patch) | |
tree | 891a2fd82432e2bd2e71127a77cc032d8069175d | |
parent | ae5696a9bb5cf2fbc589430853239586f7bcd54f (diff) |
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.
-rw-r--r-- | examples/identify.c | 4 | ||||
-rw-r--r-- | examples/manage-prints.c | 2 | ||||
-rw-r--r-- | examples/verify.c | 8 |
3 files changed, 9 insertions, 5 deletions
diff --git a/examples/identify.c b/examples/identify.c index bc2fe00..dc6a5d5 100644 --- a/examples/identify.c +++ b/examples/identify.c @@ -143,6 +143,7 @@ on_identify_cb (FpDevice *dev, FpPrint *match, FpPrint *print, if (match) { g_autoptr(FpPrint) matched_print = g_object_ref (match); + const GDate *date; char date_str[128] = {}; 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); } - 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", fp_print_get_enroll_date (matched_print)); else diff --git a/examples/manage-prints.c b/examples/manage-prints.c index 4d206cc..88200a3 100644 --- a/examples/manage-prints.c +++ b/examples/manage-prints.c @@ -161,7 +161,7 @@ on_list_completed (FpDevice *dev, finger_to_string (fp_print_get_finger (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_print (", enrolled on %s", buf); diff --git a/examples/verify.c b/examples/verify.c index 4b16323..6892ef0 100644 --- a/examples/verify.c +++ b/examples/verify.c @@ -130,12 +130,14 @@ on_match_cb (FpDevice *dev, FpPrint *match, FpPrint *print, 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; - g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0", - fp_print_get_enroll_date (match)); + if (date && g_date_valid (date)) + g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0", + fp_print_get_enroll_date (match)); g_debug ("Match report: device %s matched finger %s successifully " "with print %s, enrolled on date %s by user %s", fp_device_get_name (dev), |