diff mbox series

[2/2] util/oslib-win32: Improve error report by calling error_setg_win32()

Message ID 20200227100250.20514-3-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Improve error reporting on Windows | expand

Commit Message

Philippe Mathieu-Daudé Feb. 27, 2020, 10:02 a.m. UTC
Use error_setg_win32() which adds a hint similar to strerror(errno)).

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 util/oslib-win32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Daniel P. Berrangé Feb. 27, 2020, 10:21 a.m. UTC | #1
On Thu, Feb 27, 2020 at 11:02:50AM +0100, Philippe Mathieu-Daudé wrote:
> Use error_setg_win32() which adds a hint similar to strerror(errno)).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  util/oslib-win32.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
Markus Armbruster Feb. 27, 2020, 2:42 p.m. UTC | #2
Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  util/oslib-win32.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index e9b14ab178..d2fca1808d 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -46,7 +46,8 @@
>  void *qemu_oom_check(void *ptr)
>  {
>      if (ptr == NULL) {
> -        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());

Since we're on a path to abort(), I wouldn't bother with g_autofree.

> +        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);

Any particular reason not to use error_report()?

>          abort();
>      }
>      return ptr;
Philippe Mathieu-Daudé Feb. 27, 2020, 3:35 p.m. UTC | #3
On 2/27/20 3:42 PM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>   util/oslib-win32.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index e9b14ab178..d2fca1808d 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -46,7 +46,8 @@
>>   void *qemu_oom_check(void *ptr)
>>   {
>>       if (ptr == NULL) {
>> -        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
>> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> 
> Since we're on a path to abort(), I wouldn't bother with g_autofree.\

This is in case other developers copy that elsewhere.

> 
>> +        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);
> 
> Any particular reason not to use error_report()?

Pre-existing call, but I can change.

> 
>>           abort();
>>       }
>>       return ptr;
>
diff mbox series

Patch

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index e9b14ab178..d2fca1808d 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -46,7 +46,8 @@ 
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {
-        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);
         abort();
     }
     return ptr;