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

* [Bug libgcj/27797] win32.cc: FormatMessage fails on win98 for network messages
  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 ` pinskia at gcc dot gnu dot org
  2006-06-05 14:23 ` tromey at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-05-29 21:20 UTC (permalink / raw)
  To: java-prs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-05-29 21:20 -------
patches should be sent to java-patches@


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27797


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

* [Bug libgcj/27797] win32.cc: FormatMessage fails on win98 for network messages
  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
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at gcc dot gnu dot org @ 2006-06-05 14:23 UTC (permalink / raw)
  To: java-prs



------- Comment #2 from tromey at gcc dot gnu dot org  2006-06-05 14:23 -------
In this case won't the first failing FormatMessage change
the current error, so the next GetLastError will always
return the overwritten value?  The MSDN docs seem to indicate
that if FormatMessage fails, you can use GetLastError to find
out why...

Or maybe that is the intent?


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-06-05 14:23:56
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27797


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

* [Bug libgcj/27797] win32.cc: FormatMessage fails on win98 for network messages
  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
  3 siblings, 0 replies; 5+ messages in thread
From: r_ovidius at eml dot cc @ 2006-06-05 14:46 UTC (permalink / raw)
  To: java-prs



------- Comment #3 from r_ovidius at eml dot cc  2006-06-05 14:46 -------
The intent was to stop my app from segfaulting. :) I'm not sure what you are
getting at...

FormatMessage fails when looking up nErrorCode, since Win98 doesn't have error
messages in FORMAT_MESSAGE_FROM_SYSTEM for network messages.

The second call just does the FormatMessage on GetLastError() which is no
longer nErrorCode, but will be 317 "Message not found" due to the previous
failed call, which will be a valid MESSAGE_FROM_SYSTEM.  You could try a bunch
of other FormatMessage calls on nErrorCode with MESSAGE_FROM_HANDLE instead of
FROM_SYSTEM and try to use the ModuleHandle of wininet.dll or whatever dll and
see if that works if that is what you mean.  I haven't tried those yet since
I'm still fighting with other gcj problems.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27797


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

* [Bug libgcj/27797] win32.cc: FormatMessage fails on win98 for network messages
  2006-05-29 17:40 [Bug libgcj/27797] New: win32.cc: FormatMessage fails on win98 for network messages r_ovidius at eml dot cc
                   ` (2 preceding siblings ...)
  2006-06-05 14:46 ` r_ovidius at eml dot cc
@ 2006-06-06 18:03 ` r_ovidius at eml dot cc
  3 siblings, 0 replies; 5+ messages in thread
From: r_ovidius at eml dot cc @ 2006-06-06 18:03 UTC (permalink / raw)
  To: java-prs



------- Comment #4 from r_ovidius at eml dot cc  2006-06-06 18:03 -------
After reading more from http://tangentsoft.net/wskfaq/newbie.html [2.7], it
seems MESSAGE_FROM_MODULE won't really work. A lookup table would be needed
like in http://tangentsoft.net/wskfaq/examples/basics/ws-util.cpp for win98. 
But, the patch above still works for the time being to avoid the segfault.


-- 


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).