r191382 - PR17359: Fix off-by-one OOB on _Pragma("") and an unescaping bug
Reid Kleckner
reid at kleckner.net
Wed Sep 25 09:42:48 PDT 2013
Author: rnk
Date: Wed Sep 25 11:42:48 2013
New Revision: 191382
URL: http://llvm.org/viewvc/llvm-project?rev=191382&view=rev
Log:
PR17359: Fix off-by-one OOB on _Pragma("") and an unescaping bug
Previously the code would reduce a run of backslashes to a single
backslash, and now it will properly leave behind every other backslash.
Modified:
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/test/Preprocessor/_Pragma.c
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=191382&r1=191381&r2=191382&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Wed Sep 25 11:42:48 2013
@@ -263,14 +263,14 @@ void Preprocessor::Handle_Pragma(Token &
// Remove escaped quotes and escapes.
unsigned ResultPos = 1;
- for (unsigned i = 1, e = StrVal.size() - 2; i != e; ++i) {
- if (StrVal[i] != '\\' ||
- (StrVal[i + 1] != '\\' && StrVal[i + 1] != '"')) {
- // \\ -> '\' and \" -> '"'.
- StrVal[ResultPos++] = StrVal[i];
- }
+ for (unsigned i = 1, e = StrVal.size() - 1; i != e; ++i) {
+ // Skip escapes. \\ -> '\' and \" -> '"'.
+ if (StrVal[i] == '\\' && i + 1 < e &&
+ (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
+ ++i;
+ StrVal[ResultPos++] = StrVal[i];
}
- StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 2);
+ StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 1);
}
// Remove the front quote, replacing it with a space, so that the pragma
Modified: cfe/trunk/test/Preprocessor/_Pragma.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/_Pragma.c?rev=191382&r1=191381&r2=191382&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/_Pragma.c (original)
+++ cfe/trunk/test/Preprocessor/_Pragma.c Wed Sep 25 11:42:48 2013
@@ -5,6 +5,9 @@ _Pragma ("GCC system_header") // expect
// rdar://6880630
_Pragma("#define macro") // expected-warning {{unknown pragma ignored}}
+_Pragma("") // expected-warning {{unknown pragma ignored}}
+_Pragma("message(\"foo \\\\\\\\ bar\")") // expected-warning {{foo \\ bar}}
+
#ifdef macro
#error #define invalid
#endif
More information about the cfe-commits
mailing list