mirror of https://github.com/catchorg/Catch2.git
Don't invoke UB when nullptr is passed to StringRef constructor
This commit is contained in:
parent
e7c23b73da
commit
e484236825
|
@ -14,8 +14,8 @@
|
||||||
#include "catch_stringref.h"
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ namespace Catch {
|
||||||
|
|
||||||
StringRef::StringRef(char const* rawChars) noexcept
|
StringRef::StringRef(char const* rawChars) noexcept
|
||||||
: m_start(rawChars),
|
: m_start(rawChars),
|
||||||
m_size( static_cast<size_type>( std::strlen( rawChars ) ) )
|
m_size( (rawChars != nullptr)?
|
||||||
{
|
(static_cast<size_type>(std::strlen(rawChars))):
|
||||||
assert( rawChars != nullptr );
|
throw std::domain_error("Cannot create StringRef from nullptr"))
|
||||||
}
|
{}
|
||||||
|
|
||||||
StringRef::StringRef( char const* rawChars, size_type size ) noexcept
|
StringRef::StringRef( char const* rawChars, size_type size ) noexcept
|
||||||
: m_start( rawChars ),
|
: m_start( rawChars ),
|
||||||
|
|
Loading…
Reference in New Issue