Charusso updated this revision to Diff 206248.
Charusso added a comment.

- Test case added.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63462/new/

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/test/Analysis/dump_egraph.c


Index: clang/test/Analysis/dump_egraph.c
===================================================================
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'\\\\x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===================================================================
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+    Pos = Str.find('\\', Pos);
+    if (Pos == std::string::npos)
+      break;
+
+    // Prevent bad conversions.
+    size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+    // See whether the current backslash is not escaped.
+    if (TempPos != Str.find("\\\\", Pos)) {
+      Str.insert(Pos, "\\");
+      ++Pos; // As we insert the backslash move plus one.
+    }
+
+    ++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
     Pos = Str.find('\"', Pos);
     if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
     // Prevent bad conversions.
     size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-    // See whether the current double quote is escaped.
-    if (TempPos != Str.find("\\\"", TempPos)) {
+    // See whether the current double quote is not escaped.
+    if (TempPos != Str.find("\\\"", Pos)) {
       Str.insert(Pos, "\\");
       ++Pos; // As we insert the escape-character move plus one.
     }


Index: clang/test/Analysis/dump_egraph.c
===================================================================
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'\\\\x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===================================================================
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+    Pos = Str.find('\\', Pos);
+    if (Pos == std::string::npos)
+      break;
+
+    // Prevent bad conversions.
+    size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+    // See whether the current backslash is not escaped.
+    if (TempPos != Str.find("\\\\", Pos)) {
+      Str.insert(Pos, "\\");
+      ++Pos; // As we insert the backslash move plus one.
+    }
+
+    ++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
     Pos = Str.find('\"', Pos);
     if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
     // Prevent bad conversions.
     size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-    // See whether the current double quote is escaped.
-    if (TempPos != Str.find("\\\"", TempPos)) {
+    // See whether the current double quote is not escaped.
+    if (TempPos != Str.find("\\\"", Pos)) {
       Str.insert(Pos, "\\");
       ++Pos; // As we insert the escape-character move plus one.
     }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to