[gtk+] Avoid a crash in testcalendar
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Avoid a crash in testcalendar
- Date: Wed, 24 Dec 2014 02:48:50 +0000 (UTC)
commit 7b9065c2eea5332ec69285ccdc52106a27e25111
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 23 21:47:50 2014 -0500
Avoid a crash in testcalendar
When changing between months, we can get into a situation like
'February 30", which GDate doesn't accept. Don't crash in that
case.
tests/testcalendar.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/tests/testcalendar.c b/tests/testcalendar.c
index 4979011..16f04bf 100644
--- a/tests/testcalendar.c
+++ b/tests/testcalendar.c
@@ -67,10 +67,16 @@ calendar_date_to_string (CalendarData *data,
gtk_calendar_get_date (GTK_CALENDAR(data->window),
&year, &month, &day);
- date = g_date_new_dmy (day, month + 1, year);
- g_date_strftime (buffer, buff_len-1, "%x", date);
-
- g_date_free (date);
+ if (g_date_valid_dmy (day, month + 1, year))
+ {
+ date = g_date_new_dmy (day, month + 1, year);
+ g_date_strftime (buffer, buff_len-1, "%x", date);
+ g_date_free (date);
+ }
+ else
+ {
+ g_snprintf (buffer, buff_len - 1, "%d/%d/%d (invalid)", month + 1, day, year);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]