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

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