diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-08-24 16:03:22 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-08-24 16:06:08 +0200 |
commit | ee1946fad8a81b1917052292accafe91b7a1bb89 (patch) | |
tree | 6d5cd0b1fccfa5e78bed72f6d98f198e702644a0 /examples/execute-string.c | |
parent | 66bbda7fdc5dfdc1b0ed587a4f8cfc72b1c34a3b (diff) |
ubus: fix GCC strncpy() truncation warning
When building with gcc-10 and -O2, the following warning in ubus.c is
triggered during the compilation:
In function ‘uc_ubus_object_register’,
inlined from ‘uc_ubus_publish’ at .../ubus.c:1521:10:
.../ubus.c:1464:14: error: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
1464 | obj->name = strncpy(onptr, ubus_object_name, namelen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../ubus.c: In function ‘uc_ubus_publish’:
.../ubus.c:1447:12: note: length computed here
1447 | namelen = strlen(ubus_object_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Solve this issue by using memcpy() instead. We already take care of
allocating a zeroed, strlen() + 1 sized destination buffer so loosing
the `\0` byte of the source string is perfectly fine.
Fixes: #100
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'examples/execute-string.c')
0 files changed, 0 insertions, 0 deletions