Skip to content

Commit

Permalink
Guard std::isprint() input value [-1,255] to not trigger MSVC assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
netromdk committed May 29, 2019
1 parent 33703b2 commit 4626f45
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tracepp.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ namespace detail {

static std::string charToString(const int &val)
{
if (std::isprint(val)) {
return "'" + std::string(1, val) + "' (" + std::to_string(val) + ")";
// With MSVC in debug mode, std::isprint() triggers assertion if not: val >= -1 && val <= 255
if (val >= -1 && val <= 255 && std::isprint(val)) {
return "'" + std::string(1, static_cast<char>(val)) + "' (" + std::to_string(val) + ")";
}
return std::to_string(val);
}
Expand Down

0 comments on commit 4626f45

Please sign in to comment.