mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-01 17: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 "catch_stringref.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -43,12 +43,12 @@ namespace Catch {
|
|||||||
other.m_data = nullptr;
|
other.m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
Block a user