error-report: fix g_date_time_format assertion
PATCH 1/1 error-report: fix g_date_time_format assertion
The 'g_get_real_time' returns the number of microseconds since January 1, 1970 UTC, but 'g_date_time_new_from_unix_utc' needs the number of seconds, so it will cause the invalid time input:
(process:279642): GLib-CRITICAL (recursed) **: g_date_time_format: assertion 'datetime != NULL' failed
Call 'g_date_time_new_now' with UTC time zone, it has the same result as 'g_date_time_new_from_unix_utc(g_get_real_time()/1e6)';
--- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/error-report.c +1 -1
@@ -173,7 +173,7 @@ static char *real_time_iso8601 (void) {#if GLIB_CHECK_VERSION (2 ,62 ,0 ) -g_autoptr (GDateTime) dt =g_date_time_new_from_unix_utc (g_get_real_time ()); +g_autoptr (GDateTime) dt =g_date_time_new_now (g_time_zone_new_utc ());/* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */ #pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Signature · 1 line
2.36.0
PATCH v2 1/1 error-report: fix g_date_time_format assertion
The 'g_get_real_time' returns the number of microseconds since January 1, 1970 UTC, but 'g_date_time_new_from_unix_utc' needs the number of seconds, so it will cause the invalid time input:
(process:279642): GLib-CRITICAL (recursed) **: g_date_time_format: assertion 'datetime != NULL' failed
Call function 'g_date_time_new_now_utc' instead, it has the same result as 'g_date_time_new_from_unix_utc(g_get_real_time() / G_USEC_PER_SEC)';
---
v2: use 'g_date_time_new_now_utc' directly, which handles the time
zone reference correctly.
--- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/error-report.c +1 -1
@@ -173,7 +173,7 @@ static char *real_time_iso8601 (void) {#if GLIB_CHECK_VERSION (2 ,62 ,0 ) -g_autoptr (GDateTime) dt =g_date_time_new_from_unix_utc (g_get_real_time ()); +g_autoptr (GDateTime) dt =g_date_time_new_now_utc ();/* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */ #pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Signature · 1 line
2.36.0
Quoted 7 lines · Haiyue Wang
The '
g_get_real_time' returns the number of microseconds since January 1, 1970 UTC, but 'g_date_time_new_from_unix_utc' needs the number of seconds, so it will cause the invalid time input:(process:279642): GLib-CRITICAL (recursed) **:
g_date_time_format:
assertion 'datetime != NULL' failed
Quoted 7 lines
Call function '
g_date_time_new_now_utc' instead, it has the same result as 'g_date_time_new_from_unix_utc(g_get_real_time() / G_USEC_PER_SEC)';Fixes 73dab893b569 ("error-report: replace deprecated
g_get_current_time()with glib >= 2.62")Signed-off-by Haiyue Wang <[email protected]>
Thanks, my bad
Quoted 27 lines
---
v2: use 'g_date_time_new_now_utc' directly, which handles the time
zone reference correctly.--- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/error-report.c +1
-1@@ -173,7 +173,7 @@ static char *real_time_iso8601 (void) {#if GLIB_CHECK_VERSION (2 ,62 ,0 ) -g_autoptr (GDateTime) dt =g_date_time_new_from_unix_utc (g_get_real_time ()); +g_autoptr (GDateTime) dt =g_date_time_new_now_utc ();/* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */ #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
--
2.36.0
Signature · 1 line
Marc-André Lureau
Quoted 23 lines · Haiyue Wang
The '
g_get_real_time' returns the number of microseconds since January 1, 1970 UTC, but 'g_date_time_new_from_unix_utc' needs the number of seconds, so it will cause the invalid time input:(process:279642): GLib-CRITICAL (recursed) **:
g_date_time_format: assertion 'datetime != NULL' failedCall function '
g_date_time_new_now_utc' instead, it has the same result as 'g_date_time_new_from_unix_utc(g_get_real_time() / G_USEC_PER_SEC)';Fixes 73dab893b569 ("error-report: replace deprecated g_get_current_time() with glib >= 2.62")Signed-off-by Haiyue Wang <[email protected]>---
v2: use 'g_date_time_new_now_utc' directly, which handles the time
zone reference correctly.--- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/error-report.c +0
-0
util/error-report.c static char * · line 179
Quoted 8 lines
util/error-report.c +1
-1@@ -173,7 +173,7 @@ static char *real_time_iso8601 (void) {#if GLIB_CHECK_VERSION (2 ,62 ,0 ) -g_autoptr (GDateTime) dt =g_date_time_new_from_unix_utc (g_get_real_time ()); +g_autoptr (GDateTime) dt =g_date_time_new_now_utc ();/* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */ #pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Always nice when the bug fix is simpler than the original code too :-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Paolo Bonzini
AppliedQueued, thanks.
Paolo