diff options
author | Victor Costan <costan@gmail.com> | 2018-02-09 22:42:32 -0800 |
---|---|---|
committer | Victor Costan <costan@gmail.com> | 2018-02-12 13:02:07 -0800 |
commit | b3a1759eac70b26dc6f16562745c59030c6b927f (patch) | |
tree | 8e9bca25ef88a6bf675dc94c83729d0643c96b87 | |
parent | 222607a019638b104f67b5bd6cf7572a091500b2 (diff) | |
download | googletest-b3a1759eac70b26dc6f16562745c59030c6b927f.tar.gz googletest-b3a1759eac70b26dc6f16562745c59030c6b927f.tar.bz2 googletest-b3a1759eac70b26dc6f16562745c59030c6b927f.zip |
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.
-rw-r--r-- | googletest/src/gtest-printers.cc | 4 |
1 files changed, 3 insertions, 1 deletions
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<const unsigned char *>(str); + for (size_t i = 0; i < length; i++) { - char ch = *str++; + unsigned char ch = *s++; if (std::iscntrl(ch)) { switch (ch) { case '\t': |