From 9bea6ec04a79bb0a342ed654025c4a15d2016226 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 20 Jul 2023 07:06:32 -0700 Subject: [PATCH] Don't use deprecated checked_array_iterator --- include/fmt/format.h | 32 ++++++++------------------------ test/format-test.cc | 3 +-- test/scan.h | 4 +--- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 387d6467..4c321089 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -560,20 +560,6 @@ inline auto get_data(Container& c) -> typename Container::value_type* { return c.data(); } -#if defined(_SECURE_SCL) && _SECURE_SCL -// Make a checked iterator to avoid MSVC warnings. -template using checked_ptr = stdext::checked_array_iterator; -template -constexpr auto make_checked(T* p, size_t size) -> checked_ptr { - return {p, size}; -} -#else -template using checked_ptr = T*; -template constexpr auto make_checked(T* p, size_t) -> T* { - return p; -} -#endif - // Attempts to reserve space for n extra characters in the output range. // Returns a pointer to the reserved range or a reference to it. template ::value)> @@ -582,11 +568,11 @@ __attribute__((no_sanitize("undefined"))) #endif inline auto reserve(std::back_insert_iterator it, size_t n) - -> checked_ptr { + -> typename Container::value_type* { Container& c = get_container(it); size_t size = c.size(); c.resize(size + n); - return make_checked(get_data(c) + size, n); + return get_data(c) + size; } template @@ -618,8 +604,8 @@ template auto to_pointer(buffer_appender it, size_t n) -> T* { } template ::value)> -inline auto base_iterator(std::back_insert_iterator& it, - checked_ptr) +inline auto base_iterator(std::back_insert_iterator it, + typename Container::value_type*) -> std::back_insert_iterator { return it; } @@ -887,7 +873,7 @@ void buffer::append(const U* begin, const U* end) { try_reserve(size_ + count); auto free_cap = capacity_ - size_; if (free_cap < count) count = free_cap; - std::uninitialized_copy_n(begin, count, make_checked(ptr_ + size_, count)); + std::uninitialized_copy_n(begin, count, ptr_ + size_); size_ += count; begin += count; } @@ -957,8 +943,7 @@ class basic_memory_buffer final : public detail::buffer { // Suppress a bogus -Wstringop-overflow in gcc 13.1 (#3481). FMT_ASSERT(this->size() <= new_capacity, ""); // The following code doesn't throw, so the raw pointer above doesn't leak. - std::uninitialized_copy(old_data, old_data + this->size(), - detail::make_checked(new_data, new_capacity)); + std::uninitialized_copy(old_data, old_data + this->size(), new_data); this->set(new_data, new_capacity); // deallocate must not throw according to the standard, but even if it does, // the buffer already uses the new storage and will deallocate it in @@ -986,8 +971,7 @@ class basic_memory_buffer final : public detail::buffer { size_t size = other.size(), capacity = other.capacity(); if (data == other.store_) { this->set(store_, capacity); - detail::copy_str(other.store_, other.store_ + size, - detail::make_checked(store_, capacity)); + detail::copy_str(other.store_, other.store_ + size, store_); } else { this->set(data, capacity); // Set pointer to the inline array so that delete is not called @@ -2860,7 +2844,7 @@ class bigint { auto size = other.bigits_.size(); bigits_.resize(size); auto data = other.bigits_.data(); - std::copy(data, data + size, make_checked(bigits_.data(), size)); + std::copy(data, data + size, bigits_.data()); exp_ = other.exp_; } diff --git a/test/format-test.cc b/test/format-test.cc index 0f082f94..3e45a10f 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1674,8 +1674,7 @@ TEST(format_test, format_custom) { TEST(format_test, format_to_custom) { char buf[10] = {}; - auto end = - &*fmt::format_to(fmt::detail::make_checked(buf, 10), "{}", Answer()); + auto end = fmt::format_to(buf, "{}", Answer()); EXPECT_EQ(end, buf + 2); EXPECT_STREQ(buf, "42"); } diff --git a/test/scan.h b/test/scan.h index 6109cac5..a2cb2aa6 100644 --- a/test/scan.h +++ b/test/scan.h @@ -167,10 +167,8 @@ struct scan_handler : error_handler { void on_text(const char* begin, const char* end) { auto size = to_unsigned(end - begin); auto it = scan_ctx_.begin(); - if (it + size > scan_ctx_.end() || - !std::equal(begin, end, make_checked(it, size))) { + if (it + size > scan_ctx_.end() || !std::equal(begin, end, it)) on_error("invalid input"); - } scan_ctx_.advance_to(it + size); }