Don't invoke UB when nullptr is passed to StringRef constructor

This commit is contained in:
Martin Hořeňovský 2017-11-13 12:09:19 +01:00
parent e7c23b73da
commit e484236825
1 changed files with 7 additions and 7 deletions

View File

@ -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 ),