[thin_dump] Fix warnings on potential NULL pointer

This commit is contained in:
Ming-Hung Tsai 2021-06-02 13:08:47 +08:00
parent 2e62363446
commit 25ed2dfc9a
3 changed files with 10 additions and 16 deletions

View File

@ -25,8 +25,14 @@ command::die(string const &msg)
}
::uint64_t
command::parse_uint64(string const &str, string const &desc)
command::parse_uint64(char const *str, char const *desc)
{
if (!str) {
ostringstream out;
out << "Couldn't parse " << desc << ": NULL";
die(out.str());
}
try {
// FIXME: check trailing garbage is handled
return lexical_cast<::uint64_t>(str);

View File

@ -19,7 +19,7 @@ namespace base {
virtual ~command() {}
void die(std::string const &msg);
uint64_t parse_uint64(std::string const &str, std::string const &desc);
uint64_t parse_uint64(char const *str, char const *desc);
virtual void usage(std::ostream &out) const = 0;

View File

@ -143,7 +143,6 @@ thin_dump_cmd::run(int argc, char **argv)
int c;
char const *output = NULL;
const char shortopts[] = "hm::o:f:rV";
char *end_ptr;
block_address metadata_snap = 0;
::uint64_t dev_id;
struct flags flags;
@ -181,13 +180,7 @@ thin_dump_cmd::run(int argc, char **argv)
flags.use_metadata_snap = true;
if (optarg) {
// FIXME: deprecate this option
metadata_snap = strtoull(optarg, &end_ptr, 10);
if (end_ptr == optarg) {
cerr << "couldn't parse <metadata-snap>" << endl;
usage(cerr);
return 1;
}
metadata_snap = parse_uint64(optarg, "metadata-snap");
flags.snap_location = metadata_snap;
}
break;
@ -197,12 +190,7 @@ thin_dump_cmd::run(int argc, char **argv)
break;
case 1:
dev_id = strtoull(optarg, &end_ptr, 10);
if (end_ptr == optarg) {
cerr << "couldn't parse <dev-id>\n";
usage(cerr);
return 1;
}
dev_id = parse_uint64(optarg, "dev-id");
flags.opts.select_dev(dev_id);
break;