From 36ea307baa89088cae666d3c9134e386c08c9d57 Mon Sep 17 00:00:00 2001 From: svost Date: Wed, 30 Sep 2015 13:15:52 +0300 Subject: [PATCH] Added GetArgUInt function --- src/db.cpp | 2 +- src/rpcwallet.cpp | 4 ++-- src/util.cpp | 7 +++++++ src/util.h | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 28d6032..d857cf0 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -335,7 +335,7 @@ void CDB::Close() if (IsChainFile(strFile) && IsInitialBlockDownload()) nMinutes = 5; - bitdb.dbenv.txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100)*1024 : 0, nMinutes, 0); + bitdb.dbenv.txn_checkpoint(nMinutes ? GetArgUInt("-dblogsize", 100)*1024 : 0, nMinutes, 0); { LOCK(bitdb.cs_db); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 67c24e3..8490d3e 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1429,7 +1429,7 @@ Value keypoolrefill(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1456,7 +1456,7 @@ Value keypoolreset(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); diff --git a/src/util.cpp b/src/util.cpp index f540500..8f896d7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -595,6 +595,13 @@ int32_t GetArgInt(const std::string& strArg, int32_t nDefault) return nDefault; } +uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault) +{ + if (mapArgs.count(strArg)) + return strtoul(mapArgs[strArg]); + return nDefault; +} + bool GetBoolArg(const std::string& strArg, bool fDefault) { if (mapArgs.count(strArg)) diff --git a/src/util.h b/src/util.h index 25f6c2a..1b119d6 100644 --- a/src/util.h +++ b/src/util.h @@ -278,6 +278,16 @@ inline int32_t strtol(const std::string& str) return strtol(str.c_str(), NULL, 10); } +inline uint32_t strtoul(const char* psz) +{ + return strtoul(psz, NULL, 10); +} + +inline uint32_t strtoul(const std::string& str) +{ + return strtoul(str.c_str(), NULL, 10); +} + inline int atoi(const std::string& str) { return atoi(str.c_str()); @@ -415,6 +425,15 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault); int32_t GetArgInt(const std::string& strArg, int32_t nDefault); /** + * Return 32-bit unsigned integer argument or default value + * + * @param strArg Argument to get (e.g. "-foo") + * @param default (e.g. 1) + * @return command-line argument (0 if invalid number) or default value + */ +uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault); + +/** * Return boolean argument or default value * * @param strArg Argument to get (e.g. "-foo") -- 1.7.1