mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libvtoc: Replace strncpy() with memcpy()
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 <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user