| 10123 | GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ |
| 10124 | GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ |
| 10125 | static void UniversalPrintCharArray( |
| 10126 | const CharType* begin, size_t len, ostream* os) { |
| 10127 | // The code |
| 10128 | // const char kFoo[] = "foo"; |
| 10129 | // generates an array of 4, not 3, elements, with the last one being '\0'. |
| 10130 | // |
| 10131 | // Therefore when printing a char array, we don't print the last element if |
| 10132 | // it's '\0', such that the output matches the string literal as it's |
| 10133 | // written in the source code. |
| 10134 | if (len > 0 && begin[len - 1] == '\0') { |
| 10135 | PrintCharsAsStringTo(begin, len - 1, os); |
| 10136 | return; |
| 10137 | } |
| 10138 | |
| 10139 | // If, however, the last element in the array is not '\0', e.g. |
| 10140 | // const char kFoo[] = { 'f', 'o', 'o' }; |
| 10141 | // we must print the entire array. We also print a message to indicate |
| 10142 | // that the array is not NUL-terminated. |
| 10143 | PrintCharsAsStringTo(begin, len, os); |
| 10144 | *os << " (no terminating NUL)"; |
| 10145 | } |
| 10146 | |
| 10147 | // Prints a (const) char array of 'len' elements, starting at address 'begin'. |
| 10148 | void UniversalPrintArray(const char* begin, size_t len, ostream* os) { |
no test coverage detected