dbus-vmstate: replace g_return with error handling
PATCH 1/1 dbus-vmstate: replace g_return with error handling
From: Marc-André Lureau <[email protected]>
Since g_input_stream_read_all() may return less than requested when the stream is malformed, we should treat this condition as a runtime user error (g_return are for programming errors).
--- backends/dbus-vmstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
backends/dbus-vmstate.c +4 -1
@@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int version_id) &bytes_read, NULL, &err)) { goto error; } -g_return_val_if_fail (bytes_read == len,-1 ); +if (bytes_read != len) { +error_report ("%s: Failed to read proxy Id" , __func__); +return -1 ; + } id[len] =0 ;trace_dbus_vmstate_loading (id);
Signature · 1 line
2.29.0
Quoted 16 lines · [email protected] writes:
From: Marc-André Lureau <[email protected]>
Since
g_input_stream_read_all()may return less than requested when the stream is malformed, we should treat this condition as a runtime user error (g_returnare for programming errors).Signed-off-by Marc-André Lureau <[email protected]>--- backends/dbus-vmstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)backends/dbus-vmstate.c +0
-0
backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 233
Quoted 6 lines
backends/dbus-vmstate.c +2
-1@@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int version_id) &bytes_read, NULL, &err)) { goto error; } -g_return_val_if_fail (bytes_read == len,-1 ); +if (bytes_read != len) { +error_report ("%s: Failed to read proxy Id" , __func__);
Error messages containing function names are code smell. It's consustent with nearby errors, i.e. this patch is not to blame.
backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 238
Quoted 5 lines
backends/dbus-vmstate.c +2
-0+return -1 ; + } id[len] =0 ;trace_dbus_vmstate_loading (id);
Hi
Quoted 29 lines · Markus Armbruster
backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int
Quoted 16 lines · [email protected] writes:
From: Marc-André Lureau <[email protected]>
Since
g_input_stream_read_all()may return less than requested when the stream is malformed, we should treat this condition as a runtime user error (g_returnare for programming errors).Signed-off-by Marc-André Lureau <[email protected]>--- backends/dbus-vmstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)backends/dbus-vmstate.c +0
-0@@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int
version_id)backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 233
Quoted 6 lines
backends/dbus-vmstate.c +2
-1&bytes_read, NULL, &err)) { goto error; } -g_return_val_if_fail (bytes_read == len,-1 ); +if (bytes_read != len) { +error_report ("%s: Failed to read proxy Id" , __func__);Error messages containing function names are code smell. It's consustent with nearby errors, i.e. this patch is not to blame.
Quoted 10 lines
backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 238
Quoted 5 lines
backends/dbus-vmstate.c +2
-0+return -1 ; + } id[len] =0 ;trace_dbus_vmstate_loading (id);Reviewed-by Markus Armbruster <[email protected]>
For the record, Markus sent a similar patch later "backends/dbus-vmstate:
Fix short read error handling", which has been applied.
Signature · 1 line
Marc-André Lureau