mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
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:
@@ -155,6 +155,7 @@ namespace Catch {
|
||||
struct StringMaker<char *> {
|
||||
static std::string convert(char * str);
|
||||
};
|
||||
|
||||
#ifdef CATCH_CONFIG_WCHAR
|
||||
template<>
|
||||
struct StringMaker<wchar_t const *> {
|
||||
@@ -166,22 +167,24 @@ namespace Catch {
|
||||
};
|
||||
#endif
|
||||
|
||||
// TBD: Should we use `strnlen` to ensure that we don't go out of the buffer,
|
||||
// while keeping string semantics?
|
||||
template<int SZ>
|
||||
struct StringMaker<char[SZ]> {
|
||||
static std::string convert(const char* str) {
|
||||
static std::string convert(char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
struct StringMaker<signed char[SZ]> {
|
||||
static std::string convert(const char* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
static std::string convert(signed char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
struct StringMaker<unsigned char[SZ]> {
|
||||
static std::string convert(const char* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
static std::string convert(unsigned char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user