[WINDOWS32] Remove CRNL from FormatMessage() result string

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.
This commit is contained in:
Paul Smith 2022-12-19 00:20:06 -05:00
parent 7d8756a4a3
commit 89427039c3
3 changed files with 39 additions and 39 deletions

View file

@ -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 */

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

View 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;
}