This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/27797] New: win32.cc: FormatMessage fails on win98 for network messages
- From: "r_ovidius at eml dot cc" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 May 2006 17:39:59 -0000
- Subject: [Bug libgcj/27797] New: win32.cc: FormatMessage fails on win98 for network messages
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
gcj 4.2 trunk
FormatMessage (with MESSAGE_FROM_SYSTEM flag) doesn't work on network messages
on win98. This causes lpMsgBuf to be null, and will cause a seg fault later.
Example code:
new Socket("127.0.0.1", 7777);
(or some host/port that denies the connection).
I believe that one could explicitely try to use MESSAGE_FROM_HANDLE and
GetModuleHandle("wininet.dll") in the FORMATMESSAGE call. A quicker option was
to get the inevitable 317 (ERROR_MR_MID_NOT_FOUND) from a followup
GetLastError() call and fill the lpMsgBuf with that which is what I did to make
it work for me.
Index: win32.cc
===================================================================
--- win32.cc (revision 114200)
+++ win32.cc (working copy)
@@ -193,7 +193,7 @@
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
- FormatMessage (dwFlags,
+ DWORD fRet = FormatMessage (dwFlags,
NULL,
(DWORD) nErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
@@ -201,6 +201,17 @@
0,
NULL);
+ if (!fRet)
+ {
+ fRet = FormatMessage (dwFlags,
+ NULL,
+ (DWORD) GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL);
+ }
+
jstring ret;
if (lpszPrologue)
{
--
Summary: win32.cc: FormatMessage fails on win98 for network
messages
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: r_ovidius at eml dot cc
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27797