p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.59k stars 244 forks source link

do_from_chars(): initialize variable to fix Coverity Scan warning #353

Closed rouault closed 4 months ago

rouault commented 4 months ago

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<unsigned char, (int)10>(std::basic_string_view<char, std::char_traits<char>>)()
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