From a28a1aac1c9dc88f2e6da3ae46896b2ddb8999ab Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Sun, 17 Dec 2023 20:35:02 -0500 Subject: [PATCH] bigint test --- include/jsoncons/bigint.hpp | 10 +++++----- test/corelib/src/bigint_tests.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/jsoncons/bigint.hpp b/include/jsoncons/bigint.hpp index 7d0ca2248..292b8263f 100644 --- a/include/jsoncons/bigint.hpp +++ b/include/jsoncons/bigint.hpp @@ -48,7 +48,7 @@ namespace detail { using stored_allocator_type = allocator_type; using pointer = typename allocator_traits_type::pointer; using value_type = typename allocator_traits_type::value_type; - using size_type = typename allocator_traits_type::size_type; + using size_type = std::size_t; using pointer_traits = std::pointer_traits; basic_bigint_base() @@ -210,7 +210,7 @@ class basic_bigint : protected detail::basic_bigint_base data_(nullptr) { create(stor.length_, alloc); - std::memcpy(data_, stor.data_, stor.length_*sizeof(uint64_t)); + std::memcpy(data_, stor.data_, size_type(stor.length_*sizeof(uint64_t))); } dynamic_storage(dynamic_storage&& stor) noexcept @@ -260,7 +260,7 @@ class basic_bigint : protected detail::basic_bigint_base data_ = std::allocator_traits::allocate(alloc, capacity_new); if (length_ > 0) { - std::memcpy( data_, data_old, length_*sizeof(uint64_t)); + std::memcpy( data_, data_old, size_type(length_*sizeof(uint64_t))); } if (capacity_ > 0 && data_ != nullptr) { @@ -563,7 +563,7 @@ class basic_bigint : protected detail::basic_bigint_base common_stor_.is_negative_ = y.is_negative(); if ( y.length() > 0 ) { - std::memcpy( data(), y.data(), y.length()*sizeof(uint64_t) ); + std::memcpy( data(), y.data(), size_type(y.length()*sizeof(uint64_t)) ); } } return *this; @@ -877,7 +877,7 @@ class basic_bigint : protected detail::basic_bigint_base if ( old_length > length() ) { - memset( data() + length(), 0, size_type(old_length - length())*sizeof(uint64_t) ); + memset( data() + length(), 0, size_type(old_length - length()*sizeof(uint64_t)) ); } reduce(); diff --git a/test/corelib/src/bigint_tests.cpp b/test/corelib/src/bigint_tests.cpp index 2f4906f35..d80cb6839 100644 --- a/test/corelib/src/bigint_tests.cpp +++ b/test/corelib/src/bigint_tests.cpp @@ -369,5 +369,15 @@ TEST_CASE("bigint operations") CHECK(a == b); } + + SECTION("|=") + { + bigint a{0}; + bigint b = bigint::from_string("1277902648419017187919156692641295109476255233737630537760832794503886212911067061184379695097643279217271150419129022856601771338794256383410400076210073482253089544155377"); + bigint expected = b; + b |= a; + + CHECK(expected == b); + } }