From c15f481181d902e5c0a794828ccf22f09a5db0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Thu, 13 Sep 2018 16:08:22 +0200 Subject: [PATCH] libvtoc: Replace strncpy() with memcpy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To assemble things like the volume id or fields of the format1 label struct, strncpy() is used. Data copied here is later written to disk and we don't want any terminating null byte ('\0') there. Therefore, we can simply use memcpy() instead and get rid of the following GCC8 compile warnings: vtoc.c: In function ‘vtoc_init_format_1_8_label’: vtoc.c:747:2: warning: ‘strncpy’ output truncated before terminating nul copying 6 bytes from a s tring of the same length [-Wstringop-truncation] strncpy((char *) f1->DS1DSSN, " ", 6); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vtoc.c:746:2: warning: ‘strncpy’ output may be truncated copying 44 bytes from a string of length 79 [-Wstringop-truncation] strncpy(f1->DS1DSNAM, str, 44); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vtoc.c:761:2: warning: ‘strncpy’ output may be truncated copying 13 bytes from a string of length 79 [-Wstringop-truncation] strncpy((char *)f1->DS1SYSCD, str, 13); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vtoc.c: In function ‘vtoc_volume_label_set_volser’: vtoc.c:401:2: warning: ‘strncpy’ output may be truncated copying 6 bytes from a string of length 6 [-Wstringop-truncation] strncpy(vlabel->volid, s, VOLSER_LENGTH); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- libvtoc/vtoc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libvtoc/vtoc.c b/libvtoc/vtoc.c index 04dee02a..9208a2fb 100644 --- a/libvtoc/vtoc.c +++ b/libvtoc/vtoc.c @@ -398,7 +398,7 @@ void vtoc_volume_label_set_volser (volume_label_t *vlabel, char *volser) strcpy(s, " "); vtoc_ebcdic_enc(s, s, VOLSER_LENGTH); - strncpy(vlabel->volid, s, VOLSER_LENGTH); + memcpy(vlabel->volid, s, VOLSER_LENGTH); if (i > VOLSER_LENGTH) i = VOLSER_LENGTH; @@ -743,8 +743,8 @@ static void vtoc_init_format_1_8_label ( bzero(f1->DS1DSNAM, sizeof(f1->DS1DSNAM)); sprintf(str, "PART .NEW "); vtoc_ebcdic_enc(str, str, 44); - strncpy(f1->DS1DSNAM, str, 44); - strncpy((char *) f1->DS1DSSN, " ", 6); + memcpy(f1->DS1DSNAM, str, 44); + memcpy((char *) f1->DS1DSSN, " ", 6); f1->DS1VOLSQ = 0x0001; vtoc_set_date(&f1->DS1CREDT, @@ -758,7 +758,7 @@ static void vtoc_init_format_1_8_label ( f1->DS1NOBDB = 0x00; f1->DS1FLAG1 = 0x00; vtoc_ebcdic_enc("IBM LINUX ", str, 13); - strncpy((char *)f1->DS1SYSCD, str, 13); + memcpy((char *)f1->DS1SYSCD, str, 13); vtoc_set_date(&f1->DS1REFD, (u_int8_t) creatime->tm_year, (u_int16_t) creatime->tm_yday);