diff options
| author | Martin Hořeňovský | 2017-11-13 12:09:19 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-11-13 12:09:19 +0100 |
| commit | e484236825ef5c70eb05dfe50ca05907df29a5c0 (patch) | |
| tree | 2a2516f0ba23bd24b53402514997acf5fc0c86f8 /include/internal/catch_stringref.cpp | |
| parent | e7c23b73da9689d393ba3249479f61fc137cdba6 (diff) | |
| download | catch3-e484236825ef5c70eb05dfe50ca05907df29a5c0.tar.gz | |
Don't invoke UB when nullptr is passed to StringRef constructor
Diffstat (limited to 'include/internal/catch_stringref.cpp')
| -rw-r--r-- | include/internal/catch_stringref.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 5b6970d0..e209cf39 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -14,8 +14,8 @@ #include "catch_stringref.h" #include <ostream> -#include <cassert> #include <cstring> +#include <stdexcept> @@ -43,12 +43,12 @@ namespace Catch { other.m_data = nullptr; } - StringRef::StringRef( char const* rawChars ) noexcept - : m_start( rawChars ), - m_size( static_cast<size_type>( std::strlen( rawChars ) ) ) - { - assert( rawChars != nullptr ); - } + StringRef::StringRef(char const* rawChars) noexcept + : m_start(rawChars), + m_size( (rawChars != nullptr)? + (static_cast<size_type>(std::strlen(rawChars))): + throw std::domain_error("Cannot create StringRef from nullptr")) + {} StringRef::StringRef( char const* rawChars, size_type size ) noexcept : m_start( rawChars ), |