Skip to content

Commit

Permalink
Hotfix for byte escaping issues (#944)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Baltoli authored Dec 20, 2023
1 parent 9967b97 commit 4ca71da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,9 @@ std::string enquote(const std::string &str) {
if ((unsigned char)c >= 32 && (unsigned char)c < 127) {
result.push_back(c);
} else {
fmt::format_to(std::back_inserter(result), "\\x{:02x}", c);
fmt::format_to(
std::back_inserter(result), "\\x{:02x}",
static_cast<unsigned char>(c));
}
break;
}
Expand Down Expand Up @@ -1887,7 +1889,9 @@ static std::string escapeString(const std::string &str) {

for (char c : str) {
if (c == '"' || c == '\\' || !isprint(c)) {
fmt::format_to(std::back_inserter(result), "\\x{:02x}", c);
fmt::format_to(
std::back_inserter(result), "\\x{:02x}",
static_cast<unsigned char>(c));
} else {
result.push_back(c);
}
Expand Down

0 comments on commit 4ca71da

Please sign in to comment.