Skip to content
Commit 1e0c8356 authored by Stefan Liebler's avatar Stefan Liebler
Browse files

nis: Fix stringop-truncation warning with -O3 in nis_local_host.



When building with -O3 on s390x/x86_64, I get this stringop-truncation warning
which leads to a build fail:

In function ‘nis_local_host’,
    inlined from ‘nis_local_host’ at nis_local_names.c:147:1:
nis_local_names.c:171:11: error: ‘strncpy’ output may be truncated copying between 0 and 1023 bytes from a string of length 1024 [-Werror=stringop-truncation]
171 |           strncpy (cp, nis_local_directory (), NIS_MAXNAMELEN - len -1);
       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We can just ignore this warning as the hostname + '.' + directory-name + '\0' always fits
in __nishostname with length of (NIS_MAXNAMELEN + 1) as there is the runtime check above.
Furthermore as we already know the length of the directory-name, we can also just use
memcpy to copy the directory-name inclusive the NUL-termination.

Note: This werror was introduced with commit
32c7acd4
"Replace rawmemchr (s, '\0') with strchr"

Reviewed-by: default avatarWilco Dijkstra <Wilco.Dijkstra@arm.com>
parent 3bfdc4e2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment