Skip to content

Commit

Permalink
CPreProcessor: skip a newline after a backslash character in string o…
Browse files Browse the repository at this point in the history
…r char literals

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Jan 10, 2023
1 parent 31b3b0f commit a94bf8a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields-C={macrodef}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
X input.c /^#define X /;" d file: macrodef:"abc \\n\\t\tefg"
Y input.c /^#define Y /;" d file: macrodef:"abc"
A input.c /^#define A /;" d file: macrodef:'a'
B input.c /^#define B /;" d file: macrodef:'b'
C input.c /^#define C /;" d file: macrodef:'\\n'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#define X "abc \n\t\
efg"
#define Y "abc"

#define A '\
a'

#define B 'b'
#define C '\n'
34 changes: 26 additions & 8 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,10 +1332,19 @@ static int skipToEndOfString (bool ignoreBackslash)
{
if (c == BACKSLASH && ! ignoreBackslash)
{
vStringPutWithLimit (Cpp.charOrStringContents, c, 1024);
c = cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
if (c != EOF)
vStringPutWithLimit (Cpp.charOrStringContents, c, 1024);
int c0 = cppGetcFromUngetBufferOrFile ();
if (c0 == '\n')
continue;
if (c0 == EOF)
break;

if (vStringPutWithLimit (Cpp.charOrStringContents, c, 1024))
{
if (vStringPutWithLimit (Cpp.charOrStringContents, c0, 1024))
continue;
/* delete the last back slash at the end of the vstring. */
vStringChop(Cpp.charOrStringContents);
}
}
else if (c == DOUBLE_QUOTE)
break;
Expand Down Expand Up @@ -1410,10 +1419,19 @@ static int skipToEndOfChar ()
++count;
if (c == BACKSLASH)
{
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
c = cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
if (c != EOF)
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
int c0 = cppGetcFromUngetBufferOrFile ();
if (c0 == '\n')
continue;
if (c0 == EOF)
break;

if (vStringPutWithLimit (Cpp.charOrStringContents, c, 10))
{
if (vStringPutWithLimit (Cpp.charOrStringContents, c0, 10))
continue;
/* delete the last back slash at the end of the vstring.*/
vStringChop(Cpp.charOrStringContents);
}
}
else if (c == SINGLE_QUOTE)
break;
Expand Down

0 comments on commit a94bf8a

Please sign in to comment.