r181114 - Lex: Fix quadratic behavior when unescaping _Pragma strings.

Benjamin Kramer benny.kra at googlemail.com
Sat May 4 03:37:20 PDT 2013


Author: d0k
Date: Sat May  4 05:37:20 2013
New Revision: 181114

URL: http://llvm.org/viewvc/llvm-project?rev=181114&view=rev
Log:
Lex: Fix quadratic behavior when unescaping _Pragma strings.

No functionality change.

Modified:
    cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=181114&r1=181113&r2=181114&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sat May  4 05:37:20 2013
@@ -254,14 +254,15 @@ void Preprocessor::Handle_Pragma(Token &
            "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





More information about the cfe-commits mailing list