From 55e0fe7e0587bcab0ac0a9bc5785ccb542249fcc Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Mon, 2 Mar 2020 14:20:50 +0000 Subject: [PATCH] Fix clang -Wsign-conversion warning in bigint::subtract_bigits. subtract_bigits's index parameter is only passed to basic_memory_buffer::operator[] (size_t). subtract_bigits is only called from subtract_aligned, which passes it 'i' for the index. subtract_aligned initialises 'i' to 'other.exp_ - exp_', after asserting that other.exp_ >= exp_. As such the result of this subtraction must always be positive, and so can safely be cast to a size_t. As 'i' is only ever incremented after its assignment it too can be a size_t. --- include/fmt/format-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 4ad4df4c..2b7ea239 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -508,7 +508,7 @@ class bigint { friend struct formatter; - void subtract_bigits(int index, bigit other, bigit& borrow) { + void subtract_bigits(size_t index, bigit other, bigit& borrow) { auto result = static_cast(bigits_[index]) - other - borrow; bigits_[index] = static_cast(result); borrow = static_cast(result >> (bigit_bits * 2 - 1)); @@ -525,7 +525,7 @@ class bigint { FMT_ASSERT(other.exp_ >= exp_, "unaligned bigints"); FMT_ASSERT(compare(*this, other) >= 0, ""); bigit borrow = 0; - int i = other.exp_ - exp_; + size_t i = size_t(other.exp_ - exp_); for (size_t j = 0, n = other.bigits_.size(); j != n; ++i, ++j) { subtract_bigits(i, other.bigits_[j], borrow);