From 73d1f273084f7a50c26f1ebc9586dbbffd3d082b Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Wed, 13 Mar 2019 21:33:22 +0800
Subject: [PATCH 12/19] fix: cov: missed return value test

use the existing error paths
---
 lib/format_text/format-text.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 4e5b08e..1a6c3a3 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -468,12 +468,14 @@ static struct raw_locn *_read_metadata_location_vg(struct device_area *dev_area,
 	 */
 	memset(vgnamebuf, 0, sizeof(vgnamebuf));
 
-	dev_read_bytes(dev_area->dev, dev_area->start + rlocn->offset, NAME_LEN, vgnamebuf);
+ 	if (!dev_read_bytes(dev_area->dev, dev_area->start + rlocn->offset, NAME_LEN, vgnamebuf))
+		goto fail;
 
 	if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
 	    (isspace(vgnamebuf[len]) || vgnamebuf[len] == '{'))
 		return rlocn;
 
+fail:
 	log_error("Metadata on %s at %llu has wrong VG name \"%s\" expected %s.",
 		  dev_name(dev_area->dev),
 		  (unsigned long long)(dev_area->start + rlocn->offset),
@@ -1196,7 +1198,7 @@ int read_metadata_location_summary(const struct format_type *fmt,
 	struct raw_locn *rlocn;
 	uint32_t wrap = 0;
 	unsigned int len = 0;
-	char buf[NAME_LEN + 1] __attribute__((aligned(8)));
+	char namebuf[NAME_LEN + 1] __attribute__((aligned(8)));
 	uint64_t buffer_size, current_usage;
 
 	if (mda_free_sectors)
@@ -1221,16 +1223,17 @@ int read_metadata_location_summary(const struct format_type *fmt,
 		return 0;
 	}
 
-	dev_read_bytes(dev_area->dev, dev_area->start + rlocn->offset, NAME_LEN, buf);
-
-	while (buf[len] && !isspace(buf[len]) && buf[len] != '{' &&
+	memset(namebuf, 0, sizeof(namebuf));
+	if (!dev_read_bytes(dev_area->dev, dev_area->start + rlocn->offset, NAME_LEN, namebuf))
+		stack;
+	while (namebuf[len] && !isspace(namebuf[len]) && namebuf[len] != '{' &&
 	       len < (NAME_LEN - 1))
 		len++;
 
-	buf[len] = '\0';
+	namebuf[len] = '\0';
 
 	/* Ignore this entry if the characters aren't permissible */
-	if (!validate_name(buf)) {
+	if (!validate_name(namebuf)) {
 		log_error("Metadata location on %s at %llu begins with invalid VG name.",
 			  dev_name(dev_area->dev),
 			  (unsigned long long)(dev_area->start + rlocn->offset));
-- 
2.19.1

