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

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