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

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