]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[WINDOWS32] Remove CRNL from FormatMessage() result string
authorPaul Smith <psmith@gnu.org>
Mon, 19 Dec 2022 05:20:06 +0000 (00:20 -0500)
committerPaul Smith <psmith@gnu.org>
Mon, 19 Dec 2022 05:20:06 +0000 (00:20 -0500)
Sometimes the error message is expected to contain a newline, other
times it is not.  Also the result of FormatMessage() sometimes ends
in CRNL already: when printed via fprintf() the final newline is
converted to CRNL, giving an output of CRCRNL which causes tests
to fail to match.  Remove any CR/NL chars from the result string.

* src/job.c (reap_children): Add \n to the error message fprintf.
(exec_command): Ditto.
* src/w32/subproc/w32err.c (map_windows32_error_to_string): Remove
any trailing CR or NL from the string before returning.

src/job.c
src/w32/subproc/sub_proc.c
src/w32/subproc/w32err.c

index 876898c8436b89929faa1862b6ddd9d89cee2253..1ac64ebc339ea8d79c6d21b2d06746cbc5a4392e 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -861,7 +861,7 @@ reap_children (int block, int err)
                    map_windows32_error_to_string from calling 'fatal',
                    which will then call reap_children again */
                 if (werr && exit_code > 0 && exit_code < WSABASEERR)
-                  fprintf (stderr, "make (e=%d): %s", exit_code,
+                  fprintf (stderr, "make (e=%d): %s\n", exit_code,
                            map_windows32_error_to_string (exit_code));
 
                 /* signal */
@@ -2552,7 +2552,7 @@ exec_command (char **argv, char **envp)
       exit_code = process_exit_code (hWaitPID);
 
       if (err)
-          fprintf (stderr, "make (e=%d, rc=%d): %s",
+          fprintf (stderr, "make (e=%d, rc=%d): %s\n",
                    err, exit_code, map_windows32_error_to_string (err));
 
       /* cleanup process */
index 501afc3e6e5ba9ff4994851f62f878c426c87769..5352bf4ae74e87944446f467e6c546372e26b61f 100644 (file)
@@ -887,7 +887,7 @@ proc_stderr_thread(sub_process *pproc)
 
         for (;;) {
                 if (ReadFile( (HANDLE)pproc->sv_stderr[0], &c, 1, &nread, NULL) == FALSE) {
-                        map_windows32_error_to_string(GetLastError());
+/*                      map_windows32_error_to_string(GetLastError());*/
                         _endthreadex(0);
                 }
                 if (nread == 0)
index eb201034fd64365e8303be98527f5bd4d47b292d..ad9049cd071170fa95dd444a19990643c52d0121 100644 (file)
@@ -44,42 +44,42 @@ map_windows32_error_to_string (DWORD ercode) {
  * static.  (If and when we do need it to be in thread-local storage,
  * the corresponding GCC qualifier is '__thread'.)
  */
-    static char szMessageBuffer[128];
-        /* Fill message buffer with a default message in
-         * case FormatMessage fails
-         */
-    wsprintf (szMessageBuffer, "Error %ld\n", ercode);
+  static char szMessageBuffer[128];
+  DWORD ret;
 
-        /*
-         *  Special code for winsock error handling.
-         */
-        if (ercode > WSABASEERR) {
-#if 0
-                HMODULE hModule = GetModuleHandle("wsock32");
-                if (hModule != NULL) {
-                        FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
-                                hModule,
-                                ercode,
-                                LANG_NEUTRAL,
-                                szMessageBuffer,
-                                sizeof(szMessageBuffer),
-                                NULL);
-                        FreeLibrary(hModule);
-                }
-#else
-                O (fatal, NILF, szMessageBuffer);
-#endif
-        } else {
-                /*
-                 *  Default system message handling
-                 */
-                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
-                        NULL,
-                        ercode,
-                        LANG_NEUTRAL,
-                        szMessageBuffer,
-                        sizeof(szMessageBuffer),
-                        NULL);
+  /* Fill message buffer with a default message in
+   * case FormatMessage fails
+   */
+  wsprintf (szMessageBuffer, "Error %ld", ercode);
+
+  /*
+   *  Special code for winsock error handling.
+   */
+  if (ercode > WSABASEERR) {
+    O (fatal, NILF, szMessageBuffer);
+  }
+
+  /*
+   *  Default system message handling
+   */
+  ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
+                      NULL,
+                      ercode,
+                      LANG_NEUTRAL,
+                      szMessageBuffer,
+                      sizeof(szMessageBuffer),
+                      NULL);
+
+  if (ret)
+    {
+      char *cp;
+      for (cp = szMessageBuffer + ret - 1; cp >= szMessageBuffer; --cp)
+        {
+          if (*cp != '\r' && *cp != '\n')
+            break;
+          *cp = '\0';
         }
-    return szMessageBuffer;
+    }
+
+  return szMessageBuffer;
 }