[PATCH 2/2] cmd: Handle truncation for console reads

Frédéric Delanoy frederic.delanoy at gmail.com
Fri Sep 30 21:19:05 CDT 2011


---
 programs/cmd/batch.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 97db1b9..b99138d 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -198,7 +198,12 @@ WCHAR *WCMD_fgets(WCHAR *s, int noChars, HANDLE h, BOOL is_console_handle)
   if (is_console_handle) {
     status = ReadConsoleW(h, s, noChars, &charsRead, NULL);
     if (!status) return NULL;
-    s[charsRead-2] = '\0'; /* Strip \r\n */
+    if (s[charsRead-2] == '\r')
+      s[charsRead-2] = '\0'; /* Strip \r\n */
+    else {
+      /* Truncate */
+      s[noChars-1] = '\0';
+    }
     return p;
   }
 
-- 
1.7.6.3




More information about the wine-patches mailing list