summaryrefslogtreecommitdiff
path: root/win32/winutil.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-11-12 14:58:47 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-11-12 16:42:28 +0100
commita08a2b48b489572db89940027206020ee714afa5 (patch)
tree7f612cfa39f9ac4d78b22e2ad25f32879b729776 /win32/winutil.c
parent34dd032e4e70a33e3e8fa27e38af62f63601b447 (diff)
downloadphp-git-a08a2b48b489572db89940027206020ee714afa5.tar.gz
Strip trailing line breaks and periods from Windows error messages
PHP error messages should not contain line breaks, so we remove these from the Windows specific error messages. We also remove trailing periods for the same reason. Closes GH-6423.
Diffstat (limited to 'win32/winutil.c')
-rw-r--r--win32/winutil.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/win32/winutil.c b/win32/winutil.c
index 530dc4f0f6..a14416a6ce 100644
--- a/win32/winutil.c
+++ b/win32/winutil.c
@@ -24,7 +24,7 @@
PHP_WINUTIL_API char *php_win32_error_to_msg(HRESULT error)
{/*{{{*/
- wchar_t *bufw = NULL;
+ wchar_t *bufw = NULL, *pw;
char *buf;
DWORD ret = FormatMessageW(
@@ -36,6 +36,10 @@ PHP_WINUTIL_API char *php_win32_error_to_msg(HRESULT error)
return "";
}
+ /* strip trailing line breaks and periods */
+ for (pw = bufw + wcslen(bufw) - 1; pw >= bufw && (*pw == L'\r' || *pw == L'\n' || *pw == L'.'); pw--);
+ pw[1] = L'\0';
+
buf = php_win32_cp_conv_w_to_any(bufw, ret, PHP_WIN32_CP_IGNORE_LEN_P);
LocalFree(bufw);