Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-11-13 12:09:19 +0100
committerMartin Hořeňovský2017-11-13 12:09:19 +0100
commite484236825ef5c70eb05dfe50ca05907df29a5c0 (patch)
tree2a2516f0ba23bd24b53402514997acf5fc0c86f8 /include
parente7c23b73da9689d393ba3249479f61fc137cdba6 (diff)
downloadcatch3-e484236825ef5c70eb05dfe50ca05907df29a5c0.tar.gz
Don't invoke UB when nullptr is passed to StringRef constructor
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_stringref.cpp14
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 ),