From: Simon Marchi Date: Thu, 2 May 2019 20:53:30 +0000 (-0400) Subject: ctf: Use g_time_val_from_iso8601 instead of g_date_time_new_from_iso8601 X-Git-Tag: v2.0.0-pre5~6 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=cca91513321176e147e04c9d1457a34044f244f0 ctf: Use g_time_val_from_iso8601 instead of g_date_time_new_from_iso8601 g_date_time_new_from_iso8601 was introduced in glib 2.56, which is quite recent. To support build with older glibs, change the code to use g_time_val_from_iso8601 instead, introduced in glib 2.12. The code in question only uses this function to validate that the passed string is ISO8601-compliant, it doesn't use the resulting time value. The problem of g_time_val_from_iso8601 is that its result is not year 2038-safe on 32-bit systems. We can expect that by then, that function will have been removed from glib, forcing us to update our code. Change-Id: I2f4fdfce9020ecefcfb5d653a3885d343e49bd76 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/1245 Reviewed-by: Michael Jeanson Reviewed-by: Philippe Proulx --- diff --git a/plugins/ctf/fs-sink/fs-sink-trace.c b/plugins/ctf/fs-sink/fs-sink-trace.c index 375fff97..c6989ccc 100644 --- a/plugins/ctf/fs-sink/fs-sink-trace.c +++ b/plugins/ctf/fs-sink/fs-sink-trace.c @@ -139,18 +139,16 @@ GString *make_unique_trace_path(const char *path) static int lttng_validate_datetime(const char *datetime) { - GTimeZone *default_tz; - GDateTime *gdatetime = NULL; + GTimeVal tv; int ret = -1; - default_tz = g_time_zone_new_utc(); - if (!default_tz) { - BT_LOGD("Failed to allocate timezone"); - goto end; - } - - gdatetime = g_date_time_new_from_iso8601(datetime, default_tz); - if (!gdatetime) { + /* + * We are using g_time_val_from_iso8601, as the safer/more modern + * alternative, g_date_time_new_from_iso8601, is only available in + * glib >= 2.56, and this is sufficient for our use case of validating + * the format. + */ + if (!g_time_val_from_iso8601(datetime, &tv)) { BT_LOGD("Couldn't parse datetime as iso8601: date=\"%s\"", datetime); goto end; } @@ -158,16 +156,6 @@ int lttng_validate_datetime(const char *datetime) ret = 0; end: - if (default_tz) { - g_time_zone_unref(default_tz); - default_tz = NULL; - } - - if (gdatetime) { - g_date_time_unref(gdatetime); - gdatetime = NULL; - } - return ret; }