Commit b3a1759e by Victor Costan

Fix std::iscntrl use in gtest-printers.cc

ContainsUnprintableControlCodes() in gtest-printers.cc passes a char argument to std::iscntrl. Although its argument is an int, std::iscntrl produces undefined behavior if its argument is not representable as an unsigned char. The standard library on Windows asserts that the argument is an unsigned char, resulting in an assertion crash on debug builds.
parent 222607a0
...@@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) { ...@@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) {
namespace { namespace {
bool ContainsUnprintableControlCodes(const char* str, size_t length) { bool ContainsUnprintableControlCodes(const char* str, size_t length) {
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
for (size_t i = 0; i < length; i++) { for (size_t i = 0; i < length; i++) {
char ch = *str++; unsigned char ch = *s++;
if (std::iscntrl(ch)) { if (std::iscntrl(ch)) {
switch (ch) { switch (ch) {
case '\t': case '\t':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment