Added assertions to the CLN implementation of Integer for getLong() and getUnsignedLo...
authorTim King <taking@cs.nyu.edu>
Mon, 31 Oct 2011 21:43:11 +0000 (21:43 +0000)
committerTim King <taking@cs.nyu.edu>
Mon, 31 Oct 2011 21:43:11 +0000 (21:43 +0000)
src/util/integer_cln_imp.h

index 6e2ca35005d6877329efee46f9896975e51a9ed5..b7a35fee8848e4525928422406a909dc50d0d806 100644 (file)
@@ -29,6 +29,7 @@
 #include <cln/integer.h>
 #include <cln/input.h>
 #include <cln/integer_io.h>
+#include <limits>
 
 #include "util/Assert.h"
 
@@ -245,12 +246,14 @@ public:
   //friend std::ostream& operator<<(std::ostream& os, const Integer& n);
 
   long getLong() const {
-    // supposed to throw if not representable in type "long"
+    Assert(d_value <= std::numeric_limits<long>::max());
+    Assert(d_value >= std::numeric_limits<long>::min());
     return cln::cl_I_to_long(d_value);
   }
 
   unsigned long getUnsignedLong() const {
-    // supposed to throw if not representable in type "unsigned long"
+    Assert(d_value <= std::numeric_limits<unsigned long>::max());
+    Assert(d_value >= std::numeric_limits<unsigned long>::min());
     return cln::cl_I_to_ulong(d_value);
   }