diff mbox

[3/4] libmultipath/datacore: Remove dead code

Message ID 20170613163339.23005-4-bart.vanassche@sandisk.com (mailing list archive)
State Not Applicable, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Bart Van Assche June 13, 2017, 4:33 p.m. UTC
Remove those variables a value is assigned to but that are never
used. This patch avoids that gcc 7 reports the following warning:

datacore.c:98:22: warning: '
   ' directive output may be truncated writing 1 byte into a region of size between 0 and 8 [-Wformat-truncation=]
  snprintf(vendor, 8, "%.8s\n", inqBuffp + 8);

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
---
 libmultipath/prioritizers/datacore.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

Comments

Martin Wilck June 13, 2017, 7:31 p.m. UTC | #1
On Tue, 2017-06-13 at 09:33 -0700, Bart Van Assche wrote:
> Remove those variables a value is assigned to but that are never
> used. This patch avoids that gcc 7 reports the following warning:
> 
> datacore.c:98:22: warning: '
>    ' directive output may be truncated writing 1 byte into a region
> of size between 0 and 8 [-Wformat-truncation=]
>   snprintf(vendor, 8, "%.8s\n", inqBuffp + 8);
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> ---
>  libmultipath/prioritizers/datacore.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/libmultipath/prioritizers/datacore.c
> b/libmultipath/prioritizers/datacore.c
> index 36465ac4..59c98164 100644
> --- a/libmultipath/prioritizers/datacore.c
> +++ b/libmultipath/prioritizers/datacore.c
> @@ -35,10 +35,6 @@
>  int datacore_prio (const char *dev, int sg_fd, char * args)
>  {
>  	int k;
> -	char vendor[8];
> -	char product[32];
> -	char luname[32];
> -	char wwpn[32];
>  	char sdsname[32];
>  	unsigned char inqCmdBlk[INQ_CMD_LEN] = { INQ_CMD_CODE, 0, 0,
> 0, INQ_REPLY_LEN, 0 };
>  	unsigned char inqBuff[INQ_REPLY_LEN];
> @@ -95,11 +91,7 @@ int datacore_prio (const char *dev, int sg_fd,
> char * args)
>  	if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
>  		return 0;
>  
> -	snprintf(vendor, 8, "%.8s\n", inqBuffp + 8);
> -	snprintf(product, 17, "%.16s", inqBuffp + 16);
> -	snprintf(luname, 21, "%.19s", inqBuffp + 36);
> -	snprintf(wwpn, 17, "%.16s", inqBuffp + 96);
> -	snprintf(sdsname, 17, "%.16s", inqBuffp + 112);
> +	snprintf(sdsname, sizeof(sdsname), "%.16s", inqBuffp + 112);
>  
>  	if (strstr(sdsname , preferredsds))
>  		return 1;

I was wondering whether passing sizeof(sdsname) rather than 17 might
make a difference, and verified that that isn't the case.

Reviewed-by: Martin Wilck <mwilck@suse.com>
diff mbox

Patch

diff --git a/libmultipath/prioritizers/datacore.c b/libmultipath/prioritizers/datacore.c
index 36465ac4..59c98164 100644
--- a/libmultipath/prioritizers/datacore.c
+++ b/libmultipath/prioritizers/datacore.c
@@ -35,10 +35,6 @@ 
 int datacore_prio (const char *dev, int sg_fd, char * args)
 {
 	int k;
-	char vendor[8];
-	char product[32];
-	char luname[32];
-	char wwpn[32];
 	char sdsname[32];
 	unsigned char inqCmdBlk[INQ_CMD_LEN] = { INQ_CMD_CODE, 0, 0, 0, INQ_REPLY_LEN, 0 };
 	unsigned char inqBuff[INQ_REPLY_LEN];
@@ -95,11 +91,7 @@  int datacore_prio (const char *dev, int sg_fd, char * args)
 	if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
 		return 0;
 
-	snprintf(vendor, 8, "%.8s\n", inqBuffp + 8);
-	snprintf(product, 17, "%.16s", inqBuffp + 16);
-	snprintf(luname, 21, "%.19s", inqBuffp + 36);
-	snprintf(wwpn, 17, "%.16s", inqBuffp + 96);
-	snprintf(sdsname, 17, "%.16s", inqBuffp + 112);
+	snprintf(sdsname, sizeof(sdsname), "%.16s", inqBuffp + 112);
 
 	if (strstr(sdsname , preferredsds))
 		return 1;