Skip to content

Commit 4ca71da

Browse files
authored
Hotfix for byte escaping issues (#944)
The frontend test suite catches a bug introduced in #933, where byte literal values that overflow a signed character are printed incorrectly. I took a look at the best place to test this (i.e. whether it was worth backporting the relevant test into the backend test suite), and it is indeed in the frontend because of the way that we provide test cases in each project. I have run the downstream K test suite and verified that it passes with this fix applied. Fixes: runtimeverification/k#3883
1 parent 9967b97 commit 4ca71da

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/ast/AST.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ std::string enquote(const std::string &str) {
662662
if ((unsigned char)c >= 32 && (unsigned char)c < 127) {
663663
result.push_back(c);
664664
} else {
665-
fmt::format_to(std::back_inserter(result), "\\x{:02x}", c);
665+
fmt::format_to(
666+
std::back_inserter(result), "\\x{:02x}",
667+
static_cast<unsigned char>(c));
666668
}
667669
break;
668670
}
@@ -1887,7 +1889,9 @@ static std::string escapeString(const std::string &str) {
18871889

18881890
for (char c : str) {
18891891
if (c == '"' || c == '\\' || !isprint(c)) {
1890-
fmt::format_to(std::back_inserter(result), "\\x{:02x}", c);
1892+
fmt::format_to(
1893+
std::back_inserter(result), "\\x{:02x}",
1894+
static_cast<unsigned char>(c));
18911895
} else {
18921896
result.push_back(c);
18931897
}

0 commit comments

Comments
 (0)