From 269cc2daf3a36ad878ea1d4cb356aa38311f6e2d Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 4 May 2013 10:37:20 +0000 Subject: [PATCH] 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 --- lib/Lex/Pragma.cpp | 11 ++++++----- 1 file 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 -- 2.40.0