CheckPtr -> make_ptr (https://github.com/cppformat/cppformat/issues/50)
This commit is contained in:
parent
d142e3b55f
commit
2a747b19e0
12
format.h
12
format.h
@ -228,12 +228,12 @@ enum { INLINE_BUFFER_SIZE = 500 };
|
|||||||
#if _SECURE_SCL
|
#if _SECURE_SCL
|
||||||
// Use checked iterator to avoid warnings on MSVC.
|
// Use checked iterator to avoid warnings on MSVC.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline stdext::checked_array_iterator<T*> CheckPtr(T *ptr, std::size_t size) {
|
inline stdext::checked_array_iterator<T*> make_ptr(T *ptr, std::size_t size) {
|
||||||
return stdext::checked_array_iterator<T*>(ptr, size);
|
return stdext::checked_array_iterator<T*>(ptr, size);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T *CheckPtr(T *ptr, std::size_t) { return ptr; }
|
inline T *make_ptr(T *ptr, std::size_t) { return ptr; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// A simple array for POD types with the first SIZE elements stored in
|
// A simple array for POD types with the first SIZE elements stored in
|
||||||
@ -259,7 +259,7 @@ class Array {
|
|||||||
capacity_ = other.capacity_;
|
capacity_ = other.capacity_;
|
||||||
if (other.ptr_ == other.data_) {
|
if (other.ptr_ == other.data_) {
|
||||||
ptr_ = data_;
|
ptr_ = data_;
|
||||||
std::copy(other.data_, other.data_ + size_, CheckPtr(data_, capacity_));
|
std::copy(other.data_, other.data_ + size_, make_ptr(data_, capacity_));
|
||||||
} else {
|
} else {
|
||||||
ptr_ = other.ptr_;
|
ptr_ = other.ptr_;
|
||||||
// Set pointer to the inline array so that delete is not called
|
// Set pointer to the inline array so that delete is not called
|
||||||
@ -325,7 +325,7 @@ template <typename T, std::size_t SIZE>
|
|||||||
void Array<T, SIZE>::grow(std::size_t size) {
|
void Array<T, SIZE>::grow(std::size_t size) {
|
||||||
capacity_ = (std::max)(size, capacity_ + capacity_ / 2);
|
capacity_ = (std::max)(size, capacity_ + capacity_ / 2);
|
||||||
T *p = new T[capacity_];
|
T *p = new T[capacity_];
|
||||||
std::copy(ptr_, ptr_ + size_, CheckPtr(p, capacity_));
|
std::copy(ptr_, ptr_ + size_, make_ptr(p, capacity_));
|
||||||
if (ptr_ != data_)
|
if (ptr_ != data_)
|
||||||
delete [] ptr_;
|
delete [] ptr_;
|
||||||
ptr_ = p;
|
ptr_ = p;
|
||||||
@ -336,7 +336,7 @@ void Array<T, SIZE>::append(const T *begin, const T *end) {
|
|||||||
std::ptrdiff_t num_elements = end - begin;
|
std::ptrdiff_t num_elements = end - begin;
|
||||||
if (size_ + num_elements > capacity_)
|
if (size_ + num_elements > capacity_)
|
||||||
grow(size_ + num_elements);
|
grow(size_ + num_elements);
|
||||||
std::copy(begin, end, CheckPtr(ptr_, capacity_) + size_);
|
std::copy(begin, end, make_ptr(ptr_, capacity_) + size_);
|
||||||
size_ += num_elements;
|
size_ += num_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1311,7 +1311,7 @@ class BasicWriter {
|
|||||||
CharPtr GrowBuffer(std::size_t n) {
|
CharPtr GrowBuffer(std::size_t n) {
|
||||||
std::size_t size = buffer_.size();
|
std::size_t size = buffer_.size();
|
||||||
buffer_.resize(size + n);
|
buffer_.resize(size + n);
|
||||||
return internal::CheckPtr(&buffer_[size], n);
|
return internal::make_ptr(&buffer_[size], n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a buffer for integer formatting.
|
// Prepare a buffer for integer formatting.
|
||||||
|
Loading…
Reference in New Issue
Block a user