Skip to content

Commit

Permalink
s390: fix gcc 8 stringop-truncation warnings in proc handlers
Browse files Browse the repository at this point in the history
arch/s390/kernel/topology.c:591:3: warning: 'strncpy' output truncated
before terminating nul copying 2 bytes from a string of the same length
[-Wstringop-truncation]
   strncpy(buf, topology_is_enabled() ? "1\n" : "0\n", ARRAY_SIZE(buf));

arch/s390/appldata/appldata_base.c:326:3: warning: 'strncpy' output truncated
before terminating nul copying 2 bytes from a string of the same length
[-Wstringop-truncation]
   strncpy(buf, ops->active ? "1\n" : "0\n", ARRAY_SIZE(buf));

arch/s390/appldata/appldata_base.c:217:3: warning: 'strncpy' output truncated
before terminating nul copying 2 bytes from a string of the same length
[-Wstringop-truncation]
   strncpy(buf, appldata_timer_active ? "1\n" : "0\n", ARRAY_SIZE(buf));

To avoid the warning, just reuse memcpy.

Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Vasily Gorbik authored and Martin Schwidefsky committed Jul 2, 2018
1 parent 4e0f5e9 commit f6ea4d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions arch/s390/appldata/appldata_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ appldata_timer_handler(struct ctl_table *ctl, int write,
return 0;
}
if (!write) {
strncpy(buf, appldata_timer_active ? "1\n" : "0\n",
ARRAY_SIZE(buf));
memcpy(buf, appldata_timer_active ? "1\n" : "0\n", ARRAY_SIZE(buf));
len = strnlen(buf, ARRAY_SIZE(buf));
if (len > *lenp)
len = *lenp;
Expand Down Expand Up @@ -323,7 +322,7 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
return 0;
}
if (!write) {
strncpy(buf, ops->active ? "1\n" : "0\n", ARRAY_SIZE(buf));
memcpy(buf, ops->active ? "1\n" : "0\n", ARRAY_SIZE(buf));
len = strnlen(buf, ARRAY_SIZE(buf));
if (len > *lenp)
len = *lenp;
Expand Down
3 changes: 1 addition & 2 deletions arch/s390/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,7 @@ static int topology_ctl_handler(struct ctl_table *ctl, int write,
return 0;
}
if (!write) {
strncpy(buf, topology_is_enabled() ? "1\n" : "0\n",
ARRAY_SIZE(buf));
memcpy(buf, topology_is_enabled() ? "1\n" : "0\n", ARRAY_SIZE(buf));
len = strnlen(buf, ARRAY_SIZE(buf));
if (len > *lenp)
len = *lenp;
Expand Down

0 comments on commit f6ea4d2

Please sign in to comment.