[glib/zbrown/datetime-annotations: 3/3] gdatetime: add preconditons to public methods
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/zbrown/datetime-annotations: 3/3] gdatetime: add preconditons to public methods
- Date: Tue, 12 May 2020 11:49:30 +0000 (UTC)
commit 24322ba1fa782a734bb7d9baabdcb7c03764cb15
Author: Zander Brown <zbrown gnome org>
Date: Tue May 12 12:48:52 2020 +0100
gdatetime: add preconditons to public methods
Should make it easier to debug than segfaulting in from_instant
glib/gdatetime.c | 11 +++++++++++
1 file changed, 11 insertions(+)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 16056d299..737afdbe0 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1714,6 +1714,8 @@ GDateTime*
g_date_time_add (GDateTime *datetime,
GTimeSpan timespan)
{
+ g_return_val_if_fail (datetime != NULL, NULL);
+
return g_date_time_from_instant (datetime->tz, timespan +
g_date_time_to_instant (datetime));
}
@@ -2082,6 +2084,8 @@ g_date_time_difference (GDateTime *end,
guint
g_date_time_hash (gconstpointer datetime)
{
+ g_return_val_if_fail (datetime != NULL, 0);
+
return g_date_time_to_instant ((GDateTime *) datetime);
}
@@ -2549,6 +2553,8 @@ g_date_time_get_seconds (GDateTime *datetime)
gint64
g_date_time_to_unix (GDateTime *datetime)
{
+ g_return_val_if_fail (datetime != NULL, 0);
+
return INSTANT_TO_UNIX (g_date_time_to_instant (datetime));
}
@@ -2582,6 +2588,8 @@ gboolean
g_date_time_to_timeval (GDateTime *datetime,
GTimeVal *tv)
{
+ g_return_val_if_fail (datetime != NULL, FALSE);
+
tv->tv_sec = INSTANT_TO_UNIX (g_date_time_to_instant (datetime));
tv->tv_usec = datetime->usec % USEC_PER_SECOND;
@@ -2704,6 +2712,9 @@ GDateTime *
g_date_time_to_timezone (GDateTime *datetime,
GTimeZone *tz)
{
+ g_return_val_if_fail (datetime != NULL, NULL);
+ g_return_val_if_fail (tz != NULL, NULL);
+
return g_date_time_from_instant (tz, g_date_time_to_instant (datetime));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]