aboutsummaryrefslogtreecommitdiff
path: root/src/uint256.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-04-19 23:25:44 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-05-09 16:39:48 +0200
commit4d480c8a3fe3c58eeb083ea544c6f9e991606692 (patch)
treea071a58cad8b798c51f9c3eb9e96b0ae84e1be0b /src/uint256.h
parenteb2cbd754d0ed02ab1c3f0889b6ee1776abd5082 (diff)
Exception instead of assigning 0 in case of wrong vector length
Diffstat (limited to 'src/uint256.h')
-rw-r--r--src/uint256.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/uint256.h b/src/uint256.h
index a3f7835875..b6365bb36b 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -6,6 +6,8 @@
#ifndef BITCOIN_UINT256_H
#define BITCOIN_UINT256_H
+#include <assert.h>
+#include <stdexcept>
#include <stdint.h>
#include <stdio.h>
#include <string>
@@ -19,6 +21,11 @@ inline signed char HexDigit(char c)
return p_util_hexdigit[(unsigned char)c];
}
+class uint_error : public std::runtime_error {
+public:
+ explicit uint_error(const std::string& str) : std::runtime_error(str) {}
+};
+
/** Template base class for unsigned big integers. */
template<unsigned int BITS>
class base_uint
@@ -62,11 +69,9 @@ public:
explicit base_uint(const std::vector<unsigned char>& vch)
{
- if (vch.size() == sizeof(pn)) {
- memcpy(pn, &vch[0], sizeof(pn));
- } else {
- *this = 0;
- }
+ if (vch.size() != sizeof(pn))
+ throw uint_error("Converting vector of wrong size to base_uint");
+ memcpy(pn, &vch[0], sizeof(pn));
}
bool operator!() const