Merge from trunk rev.5048:
2012-05-22  Kai Tietz  <ktietz@redhat.com>
	* crt/crtexe.c (__mingw_winmain_hInstance): Initialize for
	console-mode, too.

git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/stable/v2.x@5141 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/ChangeLog b/mingw-w64-crt/ChangeLog
index a623205..5305202 100644
--- a/mingw-w64-crt/ChangeLog
+++ b/mingw-w64-crt/ChangeLog
@@ -1,3 +1,10 @@
+2012-06-28  Ozkan Sezer  <sezeroz@gmail.com>
+
+	Merge from trunk rev.5048:
+	2012-05-22  Kai Tietz  <ktietz@redhat.com>
+	* crt/crtexe.c (__mingw_winmain_hInstance): Initialize for
+	console-mode, too.
+
 2012-05-23  Ozkan Sezer  <sezeroz@gmail.com>
 
 	* lib32/cabinet.def: New def, based on a patch by Ray Donnelly.
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index f785694..bbdcd49 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -68,7 +68,7 @@
 
 HINSTANCE __mingw_winmain_hInstance;
 _TCHAR *__mingw_winmain_lpCmdLine;
-DWORD __mingw_winmain_nShowCmd;
+DWORD __mingw_winmain_nShowCmd = SW_SHOWDEFAULT;
 
 static int argc;
 extern void __main(void);
@@ -267,13 +267,16 @@
     
     _fpreset ();
 
-    if (mingw_app_type)
-      {
+    __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
+
 #ifdef WPRFLAG
-	lpszCommandLine = (_TCHAR *) _wcmdln;
+    lpszCommandLine = (_TCHAR *) _wcmdln;
 #else
-	lpszCommandLine = (char *) _acmdln;
+    lpszCommandLine = (char *) _acmdln;
 #endif
+
+    if (lpszCommandLine)
+      {
 	while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine && inDoubleQuote))
 	  {
 	    if (*lpszCommandLine == DQUOTECHAR)
@@ -281,8 +284,8 @@
 #ifdef _MBCS
 	    if (_ismbblead (*lpszCommandLine))
 	      {
-		if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
-		  lpszCommandLine++;
+		if (lpszCommandLine[1])
+		  ++lpszCommandLine;
 	      }
 #endif
 	    ++lpszCommandLine;
@@ -290,8 +293,11 @@
 	while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
 	  lpszCommandLine++;
 
-	__mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
 	__mingw_winmain_lpCmdLine = lpszCommandLine;
+      }
+
+    if (mingw_app_type)
+      {
 	__mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
 				    StartupInfo.wShowWindow : SW_SHOWDEFAULT;
       }
diff --git a/mingw-w64-crt/revstamp.h b/mingw-w64-crt/revstamp.h
index 766e523..5d59f98 100644
--- a/mingw-w64-crt/revstamp.h
+++ b/mingw-w64-crt/revstamp.h
@@ -1,4 +1,4 @@
 /* Do not edit. Autogenerated.  */
-#define __MINGW_W64_REV	"5100"
-#define __MINGW_W64_REV_STAMP "2012-06-15"
+#define __MINGW_W64_REV	"5140"
+#define __MINGW_W64_REV_STAMP "2012-06-28"