better Integer asserts when there's overflow on conversion to unsigned long / long
authorMorgan Deters <mdeters@gmail.com>
Wed, 2 Nov 2011 00:01:48 +0000 (00:01 +0000)
committerMorgan Deters <mdeters@gmail.com>
Wed, 2 Nov 2011 00:01:48 +0000 (00:01 +0000)
src/util/integer_cln_imp.h
src/util/integer_gmp_imp.h

index 517e406ec3a09c005779dd225182c27f03dae426..f8ffc0d6579828354919c3f71f92cf14182bde65 100644 (file)
@@ -247,15 +247,19 @@ public:
 
   long getLong() const {
     // ensure there isn't overflow
-    Assert(d_value <= std::numeric_limits<long>::max());
-    Assert(d_value >= std::numeric_limits<long>::min());
+    AlwaysAssert(d_value <= std::numeric_limits<long>::max(),
+                 "Overflow detected in Integer::getLong()");
+    AlwaysAssert(d_value >= std::numeric_limits<long>::min(),
+                 "Overflow detected in Integer::getLong()");
     return cln::cl_I_to_long(d_value);
   }
 
   unsigned long getUnsignedLong() const {
     // ensure there isn't overflow
-    Assert(d_value <= std::numeric_limits<unsigned long>::max());
-    Assert(d_value >= std::numeric_limits<unsigned long>::min());
+    AlwaysAssert(d_value <= std::numeric_limits<unsigned long>::max(),
+                 "Overflow detected in Integer::getUnsignedLong()");
+    AlwaysAssert(d_value >= std::numeric_limits<unsigned long>::min(),
+                 "Overflow detected in Integer::getUnsignedLong()");
     return cln::cl_I_to_ulong(d_value);
   }
 
index f58c0f2ffa31283f08ade47759ba73abef4baf67..16ca8313bf5f075214858f34547e5f7cebf8a60a 100644 (file)
@@ -187,13 +187,15 @@ public:
   long getLong() const {
     long si = d_value.get_si();
     // ensure there wasn't overflow
-    AlwaysAssert(mpz_cmp_si(d_value.get_mpz_t(), si) == 0);
+    AlwaysAssert(mpz_cmp_si(d_value.get_mpz_t(), si) == 0,
+                 "Overflow detected in Integer::getLong()");
     return si;
   }
   unsigned long getUnsignedLong() const {
     unsigned long ui = d_value.get_ui();
     // ensure there wasn't overflow
-    AlwaysAssert(mpz_cmp_ui(d_value.get_mpz_t(), ui) == 0);
+    AlwaysAssert(mpz_cmp_ui(d_value.get_mpz_t(), ui) == 0,
+                 "Overflow detected in Integer::getUnsignedLong()");
     return ui;
   }