Closed brunoerg closed 3 months ago
ParseInt64
There is ToIntegral
in src/util/strencodings.h
, which should be used for (almost all) new code:
/**
* Convert string to integral type T. Leading whitespace, a leading +, or any
* trailing character fail the parsing. The required format expressed as regex
* is `-?[0-9]+`. The minus sign is only permitted for signed integer types.
*
* @returns std::nullopt if the entire string could not be parsed, or if the
* parsed value is not in the range representable by the type T.
*/
template <typename T>
std::optional<T> ToIntegral(std::string_view str)
@maflcko thanks. ToIntegral
sounds better, I think we still would have some discrepancy because ToIntegral
accepts, for example, 000001, while rust-miniscript would not, but it's ok
I wouldn't mind updating rust-miniscript. But we should probably update the Miniscript BIP with the exact number format.
We got a crash on
miniscript_string
target due to validation of numbers. Forolder()
,after()
,thresh()
and maybe other fragments, Bitcoin Core accept the usage of the+
sign, e.g. (l:older(+1)
,u:after(+1)
), because ofParseInt64
function. However,rust-miniscript
checks the character itself, so it only accepts "1", "2", "3"..."9".There is a test to ensure it doesn't accept those ones: