From 51d413f89127eb218d91a4cd8480abd4bb5b7d83 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 12 Feb 2015 13:30:33 +0000 Subject: [PATCH] math: use std::array in bigints to avoid zero-sized C array errors. --- src/lol/math/bigint.h | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/lol/math/bigint.h b/src/lol/math/bigint.h index a4743611..8005a40a 100644 --- a/src/lol/math/bigint.h +++ b/src/lol/math/bigint.h @@ -31,20 +31,6 @@ namespace lol /* Avoid issues with NaCl headers */ #undef log2 -template -class bigint_digits -{ -protected: - T m_digits[N]; -}; - -template -class bigint_digits<0, T> -{ -protected: - static T const m_digits[1]; -}; - /* * A bigint stores its digits in an array of integers. The MSB of the * integers are unused. The highest used bit is the sign bit. @@ -53,7 +39,7 @@ protected: */ template -class bigint : public bigint_digits +class bigint { static int const bits_per_digit = sizeof(T) * 8 - 1; static T const digit_mask = ~((T)1 << bits_per_digit); @@ -260,12 +246,12 @@ public: */ inline bool operator ==(bigint const &x) const { - return memcmp(m_digits, x.m_digits, sizeof(m_digits)) == 0; + return m_digits == x.m_digits; } inline bool operator !=(bigint const &x) const { - return !(*this == x); + return m_digits != x.m_digits; } /* @@ -418,6 +404,9 @@ private: ret |= m_digits[digit_index + 1] << (bits_per_digit - bit_index); return ret; } + + /* Use std::array instead of C-style array to handle N == 0. */ + std::array m_digits; }; /*