diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-05-04 10:37:20 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-05-04 10:37:20 +0000 |
commit | 269cc2daf3a36ad878ea1d4cb356aa38311f6e2d (patch) | |
tree | 6b1ce6bd4939690d0d96f1188a929429d2962031 /lib/Lex/Pragma.cpp | |
parent | dc17384581e37436582a007be4d9185bcf7003ec (diff) |
Lex: Fix quadratic behavior when unescaping _Pragma strings.
No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181114 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Pragma.cpp')
-rw-r--r-- | lib/Lex/Pragma.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index b5a76fd3cb..d674ad34b4 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -254,14 +254,15 @@ void Preprocessor::Handle_Pragma(Token &Tok) { "Invalid string token!"); // Remove escaped quotes and escapes. - for (unsigned i = 1, e = StrVal.size(); i < e-2; ++i) { - if (StrVal[i] == '\\' && - (StrVal[i+1] == '\\' || StrVal[i+1] == '"')) { + 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.erase(StrVal.begin()+i); - --e; + StrVal[ResultPos++] = StrVal[i]; } } + StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 2); } // Remove the front quote, replacing it with a space, so that the pragma |