]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Don't leave idx/pos uninitialized when input str is empty 11450/head
authorFred Morcos <fred.morcos@open-xchange.com>
Fri, 25 Mar 2022 08:52:29 +0000 (09:52 +0100)
committerFred Morcos <fred.morcos@open-xchange.com>
Fri, 25 Mar 2022 09:48:55 +0000 (10:48 +0100)
pdns/misc.hh

index aee835b0634abc95e80be9a4d5f97e4e7f1fbc6c..ac725fc001683fd9a014ebf48a22a5258c703b3b 100644 (file)
@@ -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<T>::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.
  *