mirror of https://github.com/OpenTTD/OpenTTD
(svn r26496) -Fix (r1547): Reading console input on dedicated server relied on unspecified behaviour.
parent
411cca2dc3
commit
0e8bfeb7a9
|
@ -56,7 +56,7 @@
|
||||||
#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||||
|
|
||||||
/* No clear replacement. */
|
/* No clear replacement. */
|
||||||
//#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Possible future methods to mark unsafe, though needs more thought:
|
* Possible future methods to mark unsafe, though needs more thought:
|
||||||
|
|
|
@ -99,6 +99,9 @@ static void WINAPI CheckForConsoleInput()
|
||||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ReadFile(hStdin, _win_console_thread_buffer, lengthof(_win_console_thread_buffer), &nb, NULL);
|
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
|
/* Signal input waiting that input is read and wait for it being handled
|
||||||
* SignalObjectAndWait() should be used here, but it's unsupported in Win98< */
|
* SignalObjectAndWait() should be used here, but it's unsupported in Win98< */
|
||||||
SetEvent(_hInputReady);
|
SetEvent(_hInputReady);
|
||||||
|
@ -245,9 +248,7 @@ static void DedicatedHandleKeyInput()
|
||||||
SetEvent(_hWaitForInputHandling);
|
SetEvent(_hWaitForInputHandling);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* strtok() does not 'forget' \r\n if the string starts with it,
|
/* Remove trailing \r or \n */
|
||||||
* so we have to manually remove that! */
|
|
||||||
strtok(input_line, "\r\n");
|
|
||||||
for (char *c = input_line; *c != '\0'; c++) {
|
for (char *c = input_line; *c != '\0'; c++) {
|
||||||
if (*c == '\n' || *c == '\r' || c == lastof(input_line)) {
|
if (*c == '\n' || *c == '\r' || c == lastof(input_line)) {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
|
|
Loading…
Reference in New Issue