regedit: Remove next '\n' in the stream when '\r' is at the end of buffer.

Jiaxing Wang hello.wjx at gmail.com
Thu May 21 06:18:38 CDT 2015


---
 programs/regedit/regproc.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
-------------- next part --------------
From 2eaf72afaceccc06e5547be9f975c2905757a1be Mon Sep 17 00:00:00 2001
From: Jiaxing Wang <hello.wjx at gmail.com>
Date: Thu, 21 May 2015 17:27:37 +0800
Subject: regedit: Remove next '\n' in the stream when '\r' is at the end of
 buffer.

There are two cases:
Case one:
Buffer is filled as [..., '\\', '\r', 0], if the next character
in stream is '\n', the line will be truncated.
So a line like
@=hex(2):00,11,22,33,44,55,66,77,\<0d><0a>
  88,99,00,11,22,33,44,55<0d><0a>
will get:
@=hex(2):00,11,22,33,44,55,66,77,

Case two:
Buffer is filled as [..., '\r', 0], if the next character in stream
is '\n', it will be interpreted as a blank line in the next round,
causing the current key closed prematurely.
---
 programs/regedit/regproc.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index df17d74..1f277f1 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -846,6 +846,27 @@ static void processRegLinesW(FILE *in)
             if (*(s_eol-1) == '\\') {
                 WCHAR* NextLine = s_eol + 1;
 
+                /* If '\r' is at the end of the buffer, remove next '\n' and spaces in
+                 * the beginning of next line from the stream.
+                 */
+                if (*s_eol == '\r' && *(s_eol+1) == 0) {
+                    wint_t ch;
+                    do {
+                        ch = fgetwc(in);
+                    } while(ch == '\n' || ch == ' ' || ch == '\t');
+                    if (ch == WEOF) {
+                        if (ferror(in)) {
+                            perror ("While reading input");
+                            exit (IO_ERROR);
+                        } else {
+                            assert (feof(in));
+                        }
+                    } else {
+                        /* Put back other characters other than '\n' in the stream */
+                        ungetwc(ch, in);
+                    }
+                }
+
                 if(*s_eol == '\r' && *(s_eol+1) == '\n')
                     NextLine++;
 
@@ -858,6 +879,22 @@ static void processRegLinesW(FILE *in)
                 continue;
             }
 
+            /* If '\r' is at the end of the buffer, remove next '\n' in the stream */
+            if (*s_eol == '\r' && *(s_eol+1) == 0) {
+                wint_t ch = fgetwc(in);
+                if (ch == WEOF) {
+                    if (ferror(in)) {
+                        perror ("While reading input");
+                        exit (IO_ERROR);
+                    } else {
+                        assert (feof(in));
+                    }
+                } else if (ch != '\n') {
+                    /* Put back other characters other than '\n' in the stream */
+                    ungetwc(ch, in);
+                }
+            }
+
             /* Remove any line feed.  Leave s_eol on the last \0 */
             if (*s_eol == '\r' && *(s_eol + 1) == '\n')
                 *s_eol++ = '\0';
-- 
1.9.1



More information about the wine-patches mailing list