mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 02:02:42 +02:00
Merge #13815: util: Add [[nodiscard]] to all {Decode,Parse}[...](...) functions returning bool
9cc0230cfcAdd NODISCARD to all {Decode,Parse}[...](...) functions returning bool. Sort includes. (practicalswift)579497e77atests: Explicitly ignore the return value of DecodeBase58(...) (practicalswift)145fe95ec7tests: Check return value of ParseParameters(...) (practicalswift)7c5bc2a523miner: Default to DEFAULT_BLOCK_MIN_TX_FEE if unable to parse -blockmintxfee (practicalswift) Pull request description: Changes in this PR: * ~~Add linter to make sure the return value of `Parse[...](...)` is checked~~ * Add `__attribute__((warn_unused_result))` to all `{Decode,Parse}[...](...)` functions returning `bool` * Fix violations Context: * #13712: `wallet: Fix non-determinism in ParseHDKeypath(...). Avoid using an uninitialized variable in path calculation.` would have been prevented by this Tree-SHA512: 41a97899f2d5a26584235fa02b1ebfb4faacd81ea97e927022955a658fa7e15d07a1443b4b7635151a43259a1adf8f2f4de3c1c75d7b5f09f0d5496463a1dae6
This commit is contained in:
@@ -9,16 +9,17 @@
|
||||
#ifndef BITCOIN_UTIL_MONEYSTR_H
|
||||
#define BITCOIN_UTIL_MONEYSTR_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include <amount.h>
|
||||
#include <attributes.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
/* Do not use these functions to represent or parse monetary amounts to or from
|
||||
* JSON but use AmountFromValue and ValueFromAmount for that.
|
||||
*/
|
||||
std::string FormatMoney(const CAmount& n);
|
||||
bool ParseMoney(const std::string& str, CAmount& nRet);
|
||||
bool ParseMoney(const char* pszIn, CAmount& nRet);
|
||||
NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
|
||||
NODISCARD bool ParseMoney(const char* pszIn, CAmount& nRet);
|
||||
|
||||
#endif // BITCOIN_UTIL_MONEYSTR_H
|
||||
|
||||
@@ -263,7 +263,7 @@ std::string DecodeBase32(const std::string& str)
|
||||
return std::string((const char*)vchRet.data(), vchRet.size());
|
||||
}
|
||||
|
||||
static bool ParsePrechecks(const std::string& str)
|
||||
NODISCARD static bool ParsePrechecks(const std::string& str)
|
||||
{
|
||||
if (str.empty()) // No empty string allowed
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#ifndef BITCOIN_UTIL_STRENCODINGS_H
|
||||
#define BITCOIN_UTIL_STRENCODINGS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <attributes.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -92,35 +94,35 @@ constexpr inline bool IsSpace(char c) noexcept {
|
||||
* @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 occurred.
|
||||
*/
|
||||
bool ParseInt32(const std::string& str, int32_t *out);
|
||||
NODISCARD bool ParseInt32(const std::string& str, int32_t *out);
|
||||
|
||||
/**
|
||||
* Convert string to signed 64-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 occurred.
|
||||
*/
|
||||
bool ParseInt64(const std::string& str, int64_t *out);
|
||||
NODISCARD bool ParseInt64(const std::string& str, int64_t *out);
|
||||
|
||||
/**
|
||||
* Convert decimal string to unsigned 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 occurred.
|
||||
*/
|
||||
bool ParseUInt32(const std::string& str, uint32_t *out);
|
||||
NODISCARD bool ParseUInt32(const std::string& str, uint32_t *out);
|
||||
|
||||
/**
|
||||
* Convert decimal string to unsigned 64-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 occurred.
|
||||
*/
|
||||
bool ParseUInt64(const std::string& str, uint64_t *out);
|
||||
NODISCARD bool ParseUInt64(const std::string& str, uint64_t *out);
|
||||
|
||||
/**
|
||||
* Convert string to double with strict parse error feedback.
|
||||
* @returns true if the entire string could be parsed as valid double,
|
||||
* false if not the entire string could be parsed or when overflow or underflow occurred.
|
||||
*/
|
||||
bool ParseDouble(const std::string& str, double *out);
|
||||
NODISCARD bool ParseDouble(const std::string& str, double *out);
|
||||
|
||||
template<typename T>
|
||||
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
|
||||
@@ -173,7 +175,7 @@ bool TimingResistantEqual(const T& a, const T& b)
|
||||
* @returns true on success, false on error.
|
||||
* @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
|
||||
*/
|
||||
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
|
||||
NODISCARD bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
|
||||
|
||||
/** Convert from one power-of-2 number base to another. */
|
||||
template<int frombits, int tobits, bool pad, typename O, typename I>
|
||||
@@ -200,7 +202,7 @@ bool ConvertBits(const O& outfn, I it, I end) {
|
||||
}
|
||||
|
||||
/** Parse an HD keypaths like "m/7/0'/2000". */
|
||||
bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
|
||||
NODISCARD bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
|
||||
|
||||
/**
|
||||
* Converts the given character to its lowercase equivalent.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <attributes.h>
|
||||
#include <compat.h>
|
||||
#include <fs.h>
|
||||
#include <logging.h>
|
||||
@@ -159,7 +160,7 @@ public:
|
||||
*/
|
||||
void SelectConfigNetwork(const std::string& network);
|
||||
|
||||
bool ParseParameters(int argc, const char* const argv[], std::string& error);
|
||||
NODISCARD bool ParseParameters(int argc, const char* const argv[], std::string& error);
|
||||
bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user