diff --git a/format.h b/format.h index 12685608..5db241fa 100644 --- a/format.h +++ b/format.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -54,16 +55,23 @@ # define FMT_NOEXCEPT(expr) #endif -// Disable MSVC "secure" warnings. -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable: 4996) -#endif - namespace fmt { namespace internal { +#ifdef _MSC_VER +template +inline stdext::checked_array_iterator + CheckIterator(T *ptr, std::size_t size) { + return stdext::checked_array_iterator(ptr, size); +} +#else +template +inline T *CheckIterator(T *ptr, std::size_t) { + return ptr; +} +#endif // _MSC_VER + // A simple array for POD types with the first SIZE elements stored in // the object itself. It supports a subset of std::vector's operations. template @@ -123,7 +131,7 @@ template void Array::Grow(std::size_t size) { capacity_ = (std::max)(size, capacity_ + capacity_ / 2); T *p = new T[capacity_]; - std::copy(ptr_, ptr_ + size_, p); + std::copy(ptr_, ptr_ + size_, CheckIterator(p, capacity_)); if (ptr_ != data_) delete [] ptr_; ptr_ = p; @@ -1573,9 +1581,4 @@ void BasicFormatter::DoFormat() { } } -// Restore MSVC "secure" warnings. -#ifdef FMT_RESTORE_SECURE_WARNINGS -# pragma warning(pop) -#endif - #endif // FORMAT_H_