[tracker] libtracker-common: String to date conversion to return with GError when null string
- From: Andres Gomez <agomez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-common: String to date conversion to return with GError when null string
- Date: Mon, 3 Aug 2015 12:07:45 +0000 (UTC)
commit b97e8db836346b97056b07fd01d9e15e2713b3a5
Author: Andres Gomez <andres gomez jolla com>
Date: Sat Jul 18 01:03:42 2015 +0300
libtracker-common: String to date conversion to return with GError when null string
Previously we were failing with a GLIB CRITICAL.
Now, return gentlier and with a filled GError.
https://bugzilla.gnome.org/show_bug.cgi?id=752544
src/libtracker-common/tracker-date-time.c | 9 ++++++---
src/libtracker-common/tracker-date-time.h | 3 ++-
2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-common/tracker-date-time.c b/src/libtracker-common/tracker-date-time.c
index ff64e87..e8279d7 100644
--- a/src/libtracker-common/tracker-date-time.c
+++ b/src/libtracker-common/tracker-date-time.c
@@ -45,8 +45,7 @@ tracker_string_to_date (const gchar *date_string,
gint *offset_p,
GError **error)
{
- /* TODO Add more checks and use GError to report invalid input
- * as this is potential user input.
+ /* TODO Add more checks.
*/
static GRegex *regex = NULL;
@@ -58,7 +57,11 @@ tracker_string_to_date (const gchar *date_string,
gint offset;
gboolean timezoned;
- g_return_val_if_fail (date_string, -1);
+ if (!date_string) {
+ g_set_error (error, TRACKER_DATE_ERROR, TRACKER_DATE_ERROR_EMPTY,
+ "Empty date string");
+ return -1;
+ }
/* We should have a valid iso 8601 date in format
* YYYY-MM-DDThh:mm:ss with optional TZ
diff --git a/src/libtracker-common/tracker-date-time.h b/src/libtracker-common/tracker-date-time.h
index fee7ba4..78b56eb 100644
--- a/src/libtracker-common/tracker-date-time.h
+++ b/src/libtracker-common/tracker-date-time.h
@@ -32,7 +32,8 @@ G_BEGIN_DECLS
typedef enum {
TRACKER_DATE_ERROR_OFFSET,
- TRACKER_DATE_ERROR_INVALID_ISO8601
+ TRACKER_DATE_ERROR_INVALID_ISO8601,
+ TRACKER_DATE_ERROR_EMPTY
} TrackerDateError;
#define TRACKER_TYPE_DATE_TIME (tracker_date_time_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]