mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
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 <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 ),
|
||||
|
Loading…
Reference in New Issue
Block a user