public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/27797]  New: win32.cc: FormatMessage fails on win98 for network messages
@ 2006-05-29 17:40 r_ovidius at eml dot cc
  2006-05-29 21:20 ` [Bug libgcj/27797] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: r_ovidius at eml dot cc @ 2006-05-29 17:40 UTC (permalink / raw)
  To: java-prs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-06 18:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-29 17:40 [Bug libgcj/27797] New: win32.cc: FormatMessage fails on win98 for network messages r_ovidius at eml dot cc
2006-05-29 21:20 ` [Bug libgcj/27797] " pinskia at gcc dot gnu dot org
2006-06-05 14:23 ` tromey at gcc dot gnu dot org
2006-06-05 14:46 ` r_ovidius at eml dot cc
2006-06-06 18:03 ` r_ovidius at eml dot cc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).