Fix stringifying static array of unsigned chars

The fix leaves an open question: should we keep treating refs
to static array of chars as strings, or should we instead
use `strnlen` to check if it is null-terminated within the buffer

Fixes #1238
This commit is contained in:
Martin Hořeňovský
2018-04-06 11:39:40 +02:00
parent 1ca8f43b01
commit ab30621138
8 changed files with 112 additions and 14 deletions

View File

@@ -7,6 +7,8 @@
#include "catch.hpp"
#include <cstring>
namespace { namespace CompilationTests {
#ifndef COMPILATION_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
@@ -134,4 +136,15 @@ namespace { namespace CompilationTests {
REQUIRE(t1 >= t2);
}
// unsigned array
TEST_CASE("#1238") {
unsigned char uarr[] = "123";
CAPTURE(uarr);
signed char sarr[] = "456";
CAPTURE(sarr);
REQUIRE(std::memcmp(uarr, "123", sizeof(uarr)) == 0);
REQUIRE(std::memcmp(sarr, "456", sizeof(sarr)) == 0);
}
}} // namespace CompilationTests