[thin_dump] Fix warnings on potential NULL pointer
This commit is contained in:
parent
2e62363446
commit
25ed2dfc9a
@ -25,8 +25,14 @@ command::die(string const &msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
::uint64_t
|
::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 {
|
try {
|
||||||
// FIXME: check trailing garbage is handled
|
// FIXME: check trailing garbage is handled
|
||||||
return lexical_cast<::uint64_t>(str);
|
return lexical_cast<::uint64_t>(str);
|
||||||
|
@ -19,7 +19,7 @@ namespace base {
|
|||||||
virtual ~command() {}
|
virtual ~command() {}
|
||||||
|
|
||||||
void die(std::string const &msg);
|
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;
|
virtual void usage(std::ostream &out) const = 0;
|
||||||
|
@ -143,7 +143,6 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
int c;
|
int c;
|
||||||
char const *output = NULL;
|
char const *output = NULL;
|
||||||
const char shortopts[] = "hm::o:f:rV";
|
const char shortopts[] = "hm::o:f:rV";
|
||||||
char *end_ptr;
|
|
||||||
block_address metadata_snap = 0;
|
block_address metadata_snap = 0;
|
||||||
::uint64_t dev_id;
|
::uint64_t dev_id;
|
||||||
struct flags flags;
|
struct flags flags;
|
||||||
@ -181,13 +180,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
flags.use_metadata_snap = true;
|
flags.use_metadata_snap = true;
|
||||||
if (optarg) {
|
if (optarg) {
|
||||||
// FIXME: deprecate this option
|
// FIXME: deprecate this option
|
||||||
metadata_snap = strtoull(optarg, &end_ptr, 10);
|
metadata_snap = parse_uint64(optarg, "metadata-snap");
|
||||||
if (end_ptr == optarg) {
|
|
||||||
cerr << "couldn't parse <metadata-snap>" << endl;
|
|
||||||
usage(cerr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags.snap_location = metadata_snap;
|
flags.snap_location = metadata_snap;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -197,12 +190,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
dev_id = strtoull(optarg, &end_ptr, 10);
|
dev_id = parse_uint64(optarg, "dev-id");
|
||||||
if (end_ptr == optarg) {
|
|
||||||
cerr << "couldn't parse <dev-id>\n";
|
|
||||||
usage(cerr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
flags.opts.select_dev(dev_id);
|
flags.opts.select_dev(dev_id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user