Blame SOURCES/0008-thin_dump-Fix-warnings-on-potential-NULL-pointer.patch

49e81a
From 5d79a5c944d05f71425d3156597a2a61c5f2ab9a Mon Sep 17 00:00:00 2001
49e81a
From: Ming-Hung Tsai <mtsai@redhat.com>
49e81a
Date: Wed, 2 Jun 2021 13:08:47 +0800
49e81a
Subject: [PATCH 08/10] [thin_dump] Fix warnings on potential NULL pointer
49e81a
49e81a
---
49e81a
 base/application.cc            |  8 +++++++-
49e81a
 base/application.h             |  2 +-
49e81a
 thin-provisioning/thin_dump.cc | 16 ++--------------
49e81a
 3 files changed, 10 insertions(+), 16 deletions(-)
49e81a
49e81a
diff --git a/base/application.cc b/base/application.cc
49e81a
index 61338ff..dbd55a5 100644
49e81a
--- a/base/application.cc
49e81a
+++ b/base/application.cc
49e81a
@@ -25,8 +25,14 @@ command::die(string const &msg)
49e81a
 }
49e81a
 
49e81a
 ::uint64_t
49e81a
-command::parse_uint64(string const &str, string const &desc)
49e81a
+command::parse_uint64(char const *str, char const *desc)
49e81a
 {
49e81a
+	if (!str) {
49e81a
+		ostringstream out;
49e81a
+		out << "Couldn't parse " << desc << ": NULL";
49e81a
+		die(out.str());
49e81a
+	}
49e81a
+
49e81a
 	try {
49e81a
 		// FIXME: check trailing garbage is handled
49e81a
 		return lexical_cast<::uint64_t>(str);
49e81a
diff --git a/base/application.h b/base/application.h
49e81a
index b799eaf..f071533 100644
49e81a
--- a/base/application.h
49e81a
+++ b/base/application.h
49e81a
@@ -19,7 +19,7 @@ namespace base {
49e81a
 		virtual ~command() {}
49e81a
 
49e81a
 		void die(std::string const &msg;;
49e81a
-		uint64_t parse_uint64(std::string const &str, std::string const &desc);
49e81a
+		uint64_t parse_uint64(char const *str, char const *desc);
49e81a
 
49e81a
 
49e81a
 		virtual void usage(std::ostream &out) const = 0;
49e81a
diff --git a/thin-provisioning/thin_dump.cc b/thin-provisioning/thin_dump.cc
49e81a
index 74cfa91..c0e73e6 100644
49e81a
--- a/thin-provisioning/thin_dump.cc
49e81a
+++ b/thin-provisioning/thin_dump.cc
49e81a
@@ -143,7 +143,6 @@ thin_dump_cmd::run(int argc, char **argv)
49e81a
 	int c;
49e81a
 	char const *output = NULL;
49e81a
 	const char shortopts[] = "hm::o:f:rV";
49e81a
-	char *end_ptr;
49e81a
 	block_address metadata_snap = 0;
49e81a
 	::uint64_t dev_id;
49e81a
 	struct flags flags;
49e81a
@@ -181,13 +180,7 @@ thin_dump_cmd::run(int argc, char **argv)
49e81a
 			flags.use_metadata_snap = true;
49e81a
 			if (optarg) {
49e81a
 				// FIXME: deprecate this option
49e81a
-				metadata_snap = strtoull(optarg, &end_ptr, 10);
49e81a
-				if (end_ptr == optarg) {
49e81a
-					cerr << "couldn't parse <metadata-snap>" << endl;
49e81a
-					usage(cerr);
49e81a
-					return 1;
49e81a
-				}
49e81a
-
49e81a
+				metadata_snap = parse_uint64(optarg, "metadata-snap");
49e81a
 				flags.snap_location = metadata_snap;
49e81a
 			}
49e81a
 			break;
49e81a
@@ -197,12 +190,7 @@ thin_dump_cmd::run(int argc, char **argv)
49e81a
 			break;
49e81a
 
49e81a
 		case 1:
49e81a
-			dev_id = strtoull(optarg, &end_ptr, 10);
49e81a
-			if (end_ptr == optarg) {
49e81a
-				cerr << "couldn't parse <dev-id>\n";
49e81a
-				usage(cerr);
49e81a
-				return 1;
49e81a
-			}
49e81a
+			dev_id = parse_uint64(optarg, "dev-id");
49e81a
 			flags.opts.select_dev(dev_id);
49e81a
 			break;
49e81a
 
49e81a
-- 
49e81a
1.8.3.1
49e81a