From 5228c57938cd32a209a4b00a413fede3cb04b803 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 5 May 2024 21:35:55 +0200 Subject: [PATCH] do_from_chars(): initialize variable to fix Coverity Scan warning The argparse.hpp copy inside GDAL has caused Coverity Scan to emit a (false-positive) warning about x not being initialized. ``` ________________________________________________________________________________________________________ *** CID 1544814: Uninitialized variables (UNINIT) /gdal/apps/argparse/argparse.hpp: 257 in gdal_argparse::details::do_from_chars(std::basic_string_view>)() 251 if (ec == std::errc::invalid_argument) { 252 throw std::invalid_argument{"pattern '" + std::string(s) + "' not found"}; 253 } 254 if (ec == std::errc::result_out_of_range) { 255 throw std::range_error{"'" + std::string(s) + "' not representable"}; 256 } >>> CID 1544814: Uninitialized variables (UNINIT) >>> Using uninitialized value "x". ``` Let's initialize it to 0 to make the analyzer happy --- include/argparse/argparse.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index b1faa28..921a4b4 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -238,7 +238,7 @@ constexpr auto consume_hex_prefix(std::string_view s) template inline auto do_from_chars(std::string_view s) -> T { - T x; + T x{0}; auto [first, last] = pointer_range(s); auto [ptr, ec] = std::from_chars(first, last, x, Param); if (ec == std::errc()) {