fdasd: Replace strncpy() with memcpy()

While assembling the volume label, strncpy() is used. As we don't care
about NUL termination of the strings here, safely replace strncpy() with
memcpy() and get rid of the following compile warnings:

fdasd.c: In function ‘fdasd_write_vtoc_labels’:
fdasd.c:1324:4: warning: ‘strncpy’ output truncated before terminating
nul copying 44 bytes from a string of the same length
[-Wstringop-truncation]
    strncpy(ch, "LINUX.V               "
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     "                      ", 44);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fdasd.c:1332:4: warning: ‘strncpy’ output truncated before terminating
nul copying 5 bytes from a string of the same length
[-Wstringop-truncation]
    strncpy(c1, ".PART", 5);
    ^~~~~~~~~~~~~~~~~~~~~~~
In function ‘fdasd_write_vtoc_labels’,
    inlined from ‘fdasd_write_labels’ at fdasd.c:1399:3:
fdasd.c:1329:4: warning: ‘strncpy’ output may be truncated copying 6
bytes from a string of length 6 [-Wstringop-truncation]
    strncpy(c1, volser, VOLSER_LENGTH);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fdasd.c:1336:4: warning: ‘strncpy’ output may be truncated copying 5
bytes from a string of length 5 [-Wstringop-truncation]
    strncpy(c1, dsno, 5);
    ^~~~~~~~~~~~~~~~~~~~
fdasd.c:1340:4: warning: ‘strncpy’ output truncated before terminating
nul copying as many bytes from a string as its length
[-Wstringop-truncation]
    strncpy(c1, dsname, strlen(dsname)); /* We don't want \0 */
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fdasd.c:1313:4: warning: ‘strncpy’ output may be truncated copying 31
bytes from a string of length 44 [-Wstringop-truncation]
    strncpy(c1, s2, 31);
    ^~~~~~~~~~~~~~~~~~~
In function ‘fdasd_change_part_type’,
    inlined from ‘main’ at fdasd.c:3000:4:
fdasd.c:1639:3: warning: ‘strncpy’ output may be truncated copying 6
bytes from a string of length 19 [-Wstringop-truncation]
   strncpy(ch, str, 6);
   ^~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-09-20 17:20:41 +02:00
parent c2297a0a7e
commit a931428908

View File

@@ -1310,7 +1310,7 @@ static void fdasd_write_vtoc_labels(fdasd_anchor_t *anc)
volser[VOLSER_LENGTH] = ' ';
strncpy(c1, volser, VOLSER_LENGTH + 1);
c1 = strchr(ch, ' ');
strncpy(c1, s2, 31);
memcpy(c1, s2, 31);
} else {
if (get_part_type_by_dsname(ch, &part_info->type))
part_info->type = PARTITION_NATIVE;
@@ -1321,23 +1321,23 @@ static void fdasd_write_vtoc_labels(fdasd_anchor_t *anc)
setpos(anc, k, i - 1);
strncpy(ch, "LINUX.V "
memcpy(ch, "LINUX.V "
" ", 44);
strncpy(volser, anc->vlabel->volid, VOLSER_LENGTH);
vtoc_ebcdic_dec(volser, volser, VOLSER_LENGTH);
strncpy(c1, volser, VOLSER_LENGTH);
memcpy(c1, volser, VOLSER_LENGTH);
c1 = strchr(ch, ' ');
strncpy(c1, ".PART", 5);
memcpy(c1, ".PART", 5);
c1 += 5;
sprintf(dsno, "%04d.", k + 1);
strncpy(c1, dsno, 5);
memcpy(c1, dsno, 5);
c1 += 5;
get_part_dsname_by_type(part_info->type, &dsname);
strncpy(c1, dsname, strlen(dsname)); /* We don't want \0 */
memcpy(c1, dsname, strlen(dsname)); /* We don't want \0 */
}
vtoc_ebcdic_enc(ch, ch, 44);
if (anc->verbose)
@@ -1636,7 +1636,7 @@ static void fdasd_change_part_type(fdasd_anchor_t *anc)
ch = strstr(part_info->f1->DS1DSNAM, "PART") + 9;
if (ch != NULL)
strncpy(ch, str, 6);
memcpy(ch, str, 6);
vtoc_ebcdic_enc(part_info->f1->DS1DSNAM, part_info->f1->DS1DSNAM, 44);
anc->vtoc_changed++;
}