diff options
author | frosch <frosch@openttd.org> | 2014-04-24 17:49:31 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2014-04-24 17:49:31 +0000 |
commit | 0e8bfeb7a9e47473ae0c25c24f2d84d21cc88be9 (patch) | |
tree | 8e3b952e25cde6d07bba8d6824a451d3d7f608e5 /src/video | |
parent | 411cca2dc33054ee9901c559db35596807c93b7a (diff) | |
download | openttd-0e8bfeb7a9e47473ae0c25c24f2d84d21cc88be9.tar.xz |
(svn r26496) -Fix (r1547): Reading console input on dedicated server relied on unspecified behaviour.
Diffstat (limited to 'src/video')
-rw-r--r-- | src/video/dedicated_v.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index 1d8992bb7..bfe853e9a 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -99,6 +99,9 @@ static void WINAPI CheckForConsoleInput() HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); for (;;) { ReadFile(hStdin, _win_console_thread_buffer, lengthof(_win_console_thread_buffer), &nb, NULL); + if (nb >= lengthof(_win_console_thread_buffer)) nb = lengthof(_win_console_thread_buffer) - 1; + _win_console_thread_buffer[nb] = '\0'; + /* Signal input waiting that input is read and wait for it being handled * SignalObjectAndWait() should be used here, but it's unsupported in Win98< */ SetEvent(_hInputReady); @@ -245,9 +248,7 @@ static void DedicatedHandleKeyInput() SetEvent(_hWaitForInputHandling); #endif - /* strtok() does not 'forget' \r\n if the string starts with it, - * so we have to manually remove that! */ - strtok(input_line, "\r\n"); + /* Remove trailing \r or \n */ for (char *c = input_line; *c != '\0'; c++) { if (*c == '\n' || *c == '\r' || c == lastof(input_line)) { *c = '\0'; |