diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index 85fd21f051..b8d2245d67 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -93,7 +93,7 @@ std::string BmffImage::toAscii(uint32_t n) { // show 0 as _ std::replace(result.begin(), result.end(), '\0', '_'); // show non 7-bit printable ascii as . - auto f = [](unsigned char c) { return !std::isprint(c); }; + auto f = [](char c) { return c < 32 || c > 126; }; std::replace_if(result.begin(), result.end(), f, '.'); return result; } diff --git a/src/image_int.hpp b/src/image_int.hpp index b195ebd053..1f9b6f5243 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -50,8 +50,9 @@ template std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr) { for (size_t i = 0; i < binToStr.buf_.size(); ++i) { auto c = static_cast(binToStr.buf_.at(i)); - if (c != 0 || i != binToStr.buf_.size() - 1) { - if (!std::isprint(static_cast(c))) { + const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1; + if (!bTrailingNull) { + if (c < ' ' || c >= 127) { c = '.'; } stream.put(static_cast(c));