From 222b61ff9c7539beedb2e12be749ca09188e5a56 Mon Sep 17 00:00:00 2001 From: Fred Morcos Date: Fri, 25 Mar 2022 09:52:29 +0100 Subject: [PATCH] Don't leave idx/pos uninitialized when input str is empty --- pdns/misc.hh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pdns/misc.hh b/pdns/misc.hh index aee835b063..ac725fc001 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -695,7 +695,7 @@ auto checked_conv(F from) -> T * \param[in] str The input string to be converted. * * \param[in] idx Location to store the index at which processing - * stopped. + * stopped. If the input `str` is empty, `*idx` shall be set to 0. * * \param[in] base The numerical base for conversion. * @@ -707,6 +707,10 @@ auto checked_stoi(const std::string& str, size_t* idx = nullptr, int base = 10) static_assert(std::numeric_limits::is_integer, "checked_stoi: The `T` type must be an integer"); if (str.empty()) { + if (idx != nullptr) { + *idx = 0; + } + return 0; // compatibility } @@ -732,7 +736,7 @@ auto checked_stoi(const std::string& str, size_t* idx = nullptr, int base = 10) * \param[in] str The input string to be converted. * * \param[in] idx Location to store the index at which processing - * stopped. + * stopped. If the input `str` is empty, `*idx` shall be set to 0. * * \param[in] base The numerical base for conversion. * -- 2.47.2