From b3a1759eac70b26dc6f16562745c59030c6b927f Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Fri, 9 Feb 2018 22:42:32 -0800 Subject: [PATCH] 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. --- googletest/src/gtest-printers.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index fe70edcf..d55a5e9b 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) { namespace { bool ContainsUnprintableControlCodes(const char* str, size_t length) { + const unsigned char *s = reinterpret_cast(str); + for (size_t i = 0; i < length; i++) { - char ch = *str++; + unsigned char ch = *s++; if (std::iscntrl(ch)) { switch (ch) { case '\t':