Fix GCC >= 10 -Wstringop-overflow warning when build with -O3
This commit is contained in:
parent
a2ba8b9eb6
commit
6937f1a885
@ -20,10 +20,9 @@
|
||||
#define REXY_STRING_BASE_TPP
|
||||
|
||||
#include <utility> //forward, move, swap, etc
|
||||
#include <cstdlib> //memcpy
|
||||
#include <cstring> //strlen, strcpy
|
||||
|
||||
#include "utility.hpp" //max
|
||||
#include "utility.hpp" //max, memcpy
|
||||
#include "detail/string_appender.hpp"
|
||||
#include "algorithm.hpp"
|
||||
#include "compat/to_address.hpp"
|
||||
@ -88,7 +87,7 @@ namespace rexy{
|
||||
this->set_islong_flag(true);
|
||||
pointer raw = this->set_long_ptr(this->allocate(sizeof(value_type)*(cap+1)));
|
||||
if(data)
|
||||
memcpy(raw, data, sizeof(value_type)*len);
|
||||
rexy::memcpy(raw, data, sizeof(value_type)*len);
|
||||
raw[len] = 0;
|
||||
this->set_long_length(len);
|
||||
this->set_long_capacity(cap);
|
||||
@ -96,7 +95,7 @@ namespace rexy{
|
||||
this->set_islong_flag(false);
|
||||
pointer raw = this->set_short_ptr();
|
||||
if(data)
|
||||
memcpy(raw, data, sizeof(value_type)*len);
|
||||
rexy::memcpy(raw, data, sizeof(value_type)*len);
|
||||
raw[len] = 0;
|
||||
this->set_short_length(len);
|
||||
this->set_short_capacity(cap);
|
||||
@ -164,7 +163,7 @@ namespace rexy{
|
||||
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||
detail::hasallocator<Alloc>(b)
|
||||
{
|
||||
_copy_construct_string(b.get(), b.length(), b.capacity());
|
||||
_copy_construct_string(b.get(), b.length(), b.length());
|
||||
}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr basic_string<Char,Alloc>::basic_string(basic_string&& s)noexcept:
|
||||
@ -174,7 +173,7 @@ namespace rexy{
|
||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const string_base<Char>& b)
|
||||
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||
{
|
||||
_copy_construct_string(b.get(), b.length(), b.capacity());
|
||||
_copy_construct_string(b.get(), b.length(), b.length());
|
||||
}
|
||||
|
||||
//dtor
|
||||
@ -192,13 +191,14 @@ namespace rexy{
|
||||
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||
{
|
||||
if(s.length() < this->capacity()){
|
||||
memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1));
|
||||
rexy::memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1));
|
||||
this->set_length(s.length());
|
||||
return *this;
|
||||
}
|
||||
}else{
|
||||
basic_string tmp(s);
|
||||
return (*this = std::move(tmp));
|
||||
}
|
||||
}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(basic_string&& s)noexcept{
|
||||
string_base<Char>::operator=(std::move(s));
|
||||
@ -270,7 +270,7 @@ namespace rexy{
|
||||
pointer raw = this->get_pointer();
|
||||
|
||||
if(mylen+len <= mycap){
|
||||
memcpy(raw+mylen, data, sizeof(value_type)*len);
|
||||
rexy::memcpy(raw+mylen, data, sizeof(value_type)*len);
|
||||
this->set_length(mylen+len);
|
||||
raw[mylen+len] = 0;
|
||||
}else{
|
||||
@ -336,7 +336,7 @@ namespace rexy{
|
||||
size_type len = this->get_short_length();
|
||||
pointer raw = this->get_short_ptr();
|
||||
pointer retval = this->allocate(sizeof(value_type)*len+1);
|
||||
memcpy(retval, raw, sizeof(value_type)*len);
|
||||
rexy::memcpy(retval, raw, sizeof(value_type)*len);
|
||||
retval[len] = 0;
|
||||
raw[0] = 0;
|
||||
this->set_short_length(0);
|
||||
@ -361,7 +361,7 @@ namespace rexy{
|
||||
if(len <= this->length()){
|
||||
this->set_length(len);
|
||||
pointer raw = this->get_pointer();
|
||||
memcpy(raw, s, sizeof(value_type)*len);
|
||||
rexy::memcpy(raw, s, sizeof(value_type)*len);
|
||||
raw[len] = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user