[2/2] cmd: Handle truncation for console reads (try 2)

Frédéric Delanoy frederic.delanoy at gmail.com
Sat Oct 1 06:36:36 CDT 2011


This is needed so callers (e.g. WCMD_ReadAndParseLine) can actually catch the truncation, and act accordingly.
Non-truncated lines are terminated by \r\n
---
 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 df7ae4c..5f317bc 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