aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-03 10:20:58 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-09 16:45:56 +0200
commit0d4ea1cf8a349cf59795ac68645afe70e98c6b3a (patch)
tree10aaa665a70c821e0f9773c190e47fa330adcc11 /src/util.h
parente443ed2462b706650f51f08c8760dbf5047aa77f (diff)
downloadbitcoin-0d4ea1cf8a349cf59795ac68645afe70e98c6b3a.tar.xz
util: add parseint32 function with strict error reporting
None of the current integer parsing functions in util check whether the result is valid and fits in the range of the type. This is required for less sloppy error reporting.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index fbd841f7a8..fa1e664c92 100644
--- a/src/util.h
+++ b/src/util.h
@@ -256,6 +256,13 @@ inline int atoi(const std::string& str)
return atoi(str.c_str());
}
+/**
+ * Convert string to signed 32-bit integer with strict parse error feedback.
+ * @returns true if the entire string could be parsed as valid integer,
+ * false if not the entire string could be parsed or when overflow or underflow occured.
+ */
+bool ParseInt32(const std::string& str, int32_t *out);
+
inline int roundint(double d)
{
return (int)(d > 0 ? d + 0.5 : d - 0.5);