Fix throw_winerror_with_name build error on x86-64 Cygwin

Message ID 20240223165556.1006879-1-pedro@palves.net
State New
Headers
Series Fix throw_winerror_with_name build error on x86-64 Cygwin |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged

Commit Message

Pedro Alves Feb. 23, 2024, 4:55 p.m. UTC
  The GDB build currently fails on x86-64 Cygwin, with:

 src/gdbsupport/errors.cc: In function ‘void throw_winerror_with_name(const char*, ULONGEST)’:
 src/gdbsupport/errors.cc:152:12: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ULONGEST’ {aka ‘long unsigned int’} [-Werror=format=]
   152 |   error (_("%s (error %d): %s"), string, err, strwinerror (err));
       |            ^

Fix this by adding a cast.  While at it, the error codes are really a
DWORD that results from a GetLastError() call, so I think unsigned is
more appropriate.  That is also what strwinerror already does:

    sprintf (buf, "unknown win32 error (%u)", (unsigned) error);

The cast is necessary on MinGW GDB as well, where ULONGEST is unsigned
long long, but for some reason, I don't get a warning there.

Change-Id: I3f5faa779765fd8021abf58bb5f68d556b309d17
---
 gdbsupport/errors.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: e433bca4847acd34b6178a392335ed10060639ec
  

Comments

Tom Tromey Feb. 23, 2024, 5:05 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> Fix this by adding a cast.  While at it, the error codes are really a
Pedro> DWORD that results from a GetLastError() call, so I think unsigned is
Pedro> more appropriate.  That is also what strwinerror already does:

Pedro>     sprintf (buf, "unknown win32 error (%u)", (unsigned) error);

Pedro> The cast is necessary on MinGW GDB as well, where ULONGEST is unsigned
Pedro> long long, but for some reason, I don't get a warning there.

Looks good, thank you.  I don't know why I haven't tripped over this.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdbsupport/errors.cc b/gdbsupport/errors.cc
index 8ac3ed0da79..cccdc5cafb2 100644
--- a/gdbsupport/errors.cc
+++ b/gdbsupport/errors.cc
@@ -149,7 +149,7 @@  strwinerror (ULONGEST error)
 void
 throw_winerror_with_name (const char *string, ULONGEST err)
 {
-  error (_("%s (error %d): %s"), string, err, strwinerror (err));
+  error (_("%s (error %u): %s"), string, (unsigned) err, strwinerror (err));
 }
 
 #endif /* USE_WIN32API */