Skip to contentSkip to conversation

fix compiler warnings

PATCH In review Eric DeVolder 2 participants 2 messages Jul 12, 2017 – Jul 14, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix compiler warnings

When building makedumpfile with GCC 5.4, I observe a few warnings:

% make LINKTYPE=dynamic

sadump_info.c: In function ‘sadump_is_dumpable’:
sadump_info.c:145:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^
In file included from sadump_info.c:21:0:
makedumpfile.h: In function ‘is_dumpable_file’:
makedumpfile.h:1992:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^
makedumpfile.c: In function ‘write_eraseinfo’:
makedumpfile.c:8273:4: warning: format not a string literal and no format arguments [-Wformat-security]

    DEBUG_MSG(obuf);
    ^

makedumpfile.c:8273:4: warning: format not a string literal and no format arguments [-Wformat-security] In file included from makedumpfile.c:16:0:
makedumpfile.h: In function ‘is_dumpable_file’:
makedumpfile.h:1992:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^

This patch eliminates the warnings.

---
v1: 12jul2017 posted to kexec-tools mailing list

---
 makedumpfile.c | 2 +-
 makedumpfile.h | 6 +++++-
 sadump_info.c  | 6 +++++-
 3 files changed, 11 insertions(+), 3 deletions(-)
makedumpfile.c +1 -1
index e69b6df..8b8a6b0 100644
@@ -8270,7 +8270,7 @@ write_eraseinfo(struct cache_data *cd_page, unsigned long *size_out)
 			}
 			sprintf(obuf, "erase %s %s", erase_info[i].symbol_expr,
 							size_str);
-			DEBUG_MSG(obuf);
+			DEBUG_MSG("%s", obuf);
 			if (!write_cache(cd_page, obuf, strlen(obuf)))
 				goto out;
 			size_eraseinfo += strlen(obuf);
makedumpfile.h +5 -1
index e32e567..38ea673 100644
@@ -1981,6 +1981,7 @@ static inline int
 is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
 	off_t offset;
+	ssize_t rcode;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
@@ -1989,7 +1990,10 @@ is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 			return FALSE;
 		}
 
-		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		if (rcode != BUFSIZE_BITMAP)
+			ERRMSG("Can't read the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
 		if (pfn == 0)
 			bitmap->no_block = 0;
 		else
sadump_info.c +5 -1
index f77a020..9a6b977 100644
@@ -138,11 +138,15 @@ static inline int
 sadump_is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
 	off_t offset;
+	ssize_t rcode;
 
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		lseek(bitmap->fd, offset, SEEK_SET);
-		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		if (rcode != BUFSIZE_BITMAP)
+			ERRMSG("Can't read the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
 		if (pfn == 0)
 			bitmap->no_block = 0;
 		else
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hello Eric,

Thanks, I'll merge this into v1.6.2.

Regards,
Atsushi Kumagai

Quoted 97 lines

When building makedumpfile with GCC 5.4, I observe a few warnings:

% make LINKTYPE=dynamic

sadump_info.c: In function ‘sadump_is_dumpable’:
sadump_info.c:145:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^
In file included from sadump_info.c:21:0:
makedumpfile.h: In function ‘is_dumpable_file’:
makedumpfile.h:1992:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^
makedumpfile.c: In function ‘write_eraseinfo’:
makedumpfile.c:8273:4: warning: format not a string literal and no format arguments [-Wformat-security]

   DEBUG_MSG(obuf);
   ^

makedumpfile.c:8273:4: warning: format not a string literal and no format arguments [-Wformat-security] In file included from makedumpfile.c:16:0:
makedumpfile.h: In function ‘is_dumpable_file’:
makedumpfile.h:1992:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
^

This patch eliminates the warnings.

---
v1: 12jul2017 posted to kexec-tools mailing list
---

makedumpfile.c | 2 +-
makedumpfile.h | 6 +++++-
sadump_info.c  | 6 +++++-
3 files changed, 11 insertions(+), 3 deletions(-)
makedumpfile.c +1 -1
index e69b6df..8b8a6b0 100644
@@ -8270,7 +8270,7 @@ write_eraseinfo(struct cache_data *cd_page, unsigned long *size_out)
 			}
 			sprintf(obuf, "erase %s %s", erase_info[i].symbol_expr,
 							size_str);
-			DEBUG_MSG(obuf);
+			DEBUG_MSG("%s", obuf);
 			if (!write_cache(cd_page, obuf, strlen(obuf)))
 				goto out;
 			size_eraseinfo += strlen(obuf);
makedumpfile.h +5 -1
index e32e567..38ea673 100644
@@ -1981,6 +1981,7 @@ static inline int
 is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
 	off_t offset;
+	ssize_t rcode;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
@@ -1989,7 +1990,10 @@ is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 			return FALSE;
 		}
 
-		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		if (rcode != BUFSIZE_BITMAP)
+			ERRMSG("Can't read the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
 		if (pfn == 0)
 			bitmap->no_block = 0;
 		else
sadump_info.c +5 -2
index f77a020..9a6b977 100644
@@ -138,11 +138,15 @@ static inline int
 sadump_is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
 	off_t offset;
+	ssize_t rcode;
 
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		lseek(bitmap->fd, offset, SEEK_SET);
-		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
+		if (rcode != BUFSIZE_BITMAP)
+			ERRMSG("Can't read the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
 		if (pfn == 0)
 			bitmap->no_block = 0;
 		else
--
Quoted 1 line

2.7.4

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec