[mdadm PATCH 3/3] Replace snprintf with strncpy to avoid building error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are some building errors like:
super-intel.c: In function 'imsm_process_update':
super-intel.c:9834:58: error: '__builtin_snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
   snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, %s, name);
                                                          ^
Use strncpy to avoid the building error.

Signed-off-by: Xiao Ni <xni@xxxxxxxxxx>
---
 super-intel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/super-intel.c b/super-intel.c
index 520abf5..91b97db 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -1928,7 +1928,7 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
 	strncpy(str, (char *)mpb->sig, MPB_SIG_LEN);
 	str[MPB_SIG_LEN-1] = '\0';
 	printf("          Magic : %s\n", str);
-	snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb));
+	strncpy(str, (char *)get_imsm_version(mpb), strlen(MPB_VERSION_RAID0));
 	printf("        Version : %s\n", get_imsm_version(mpb));
 	printf("    Orig Family : %08x\n", __le32_to_cpu(mpb->orig_family_num));
 	printf("         Family : %08x\n", __le32_to_cpu(mpb->family_num));
@@ -9876,7 +9876,7 @@ static void imsm_process_update(struct supertype *st,
 		/* sanity check that we are not affecting the uuid of
 		 * an active array
 		 */
-		snprintf(name, MAX_RAID_SERIAL_LEN, "%s", (char *) u->name);
+		strncpy(name, (char *) u->name, MAX_RAID_SERIAL_LEN);
 		name[MAX_RAID_SERIAL_LEN] = '\0';
 		for (a = st->arrays; a; a = a->next)
 			if (a->info.container_member == target)
@@ -9887,7 +9887,7 @@ static void imsm_process_update(struct supertype *st,
 			break;
 		}
 
-		snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
+		strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
 		super->updates_pending++;
 		break;
 	}
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux