[PATCH] D63462: [analyzer] JsonSupport: Escape escapes
Csaba Dabis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 24 20:09:57 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364270: [analyzer] JsonSupport: Escape escapes (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D63462?vs=206357&id=206358#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63462/new/
https://reviews.llvm.org/D63462
Files:
cfe/trunk/include/clang/Basic/JsonSupport.h
cfe/trunk/test/Analysis/dump_egraph.c
cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
Index: cfe/trunk/include/clang/Basic/JsonSupport.h
===================================================================
--- cfe/trunk/include/clang/Basic/JsonSupport.h
+++ cfe/trunk/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: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
===================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -15,7 +15,7 @@
// CHECK: <td align="left"><b>Environment: </b></td>
// CHECK-SAME: <td align="left">"foo"</td>
// CHECK-SAME: <td align="left">&Element\{"foo",0 S64b,char\}</td>
- const char *const foo = "foo";
+ const char *const foo = "\x66\x6f\x6f";
// CHECK: <font color="cyan3">BinaryOperator</font>
// CHECK-SAME: <td align="left">1 \| 2</td>
Index: cfe/trunk/test/Analysis/dump_egraph.c
===================================================================
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/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'\"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63462.206358.patch
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190625/4cb93b86/attachment.bin>
More information about the cfe-commits
mailing list