summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-24 16:03:22 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-24 16:06:08 +0200
commitee1946fad8a81b1917052292accafe91b7a1bb89 (patch)
tree6d5cd0b1fccfa5e78bed72f6d98f198e702644a0 /lib
parent66bbda7fdc5dfdc1b0ed587a4f8cfc72b1c34a3b (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 'lib')
-rw-r--r--lib/ubus.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/ubus.c b/lib/ubus.c
index 7f30fb8..4766119 100644
--- a/lib/ubus.c
+++ b/lib/ubus.c
@@ -1461,7 +1461,7 @@ uc_ubus_object_register(struct ubus_context *ctx, const char *ubus_object_name,
method = (struct ubus_method *)mptr;
obj = &uuobj->obj;
- obj->name = strncpy(onptr, ubus_object_name, namelen);
+ obj->name = memcpy(onptr, ubus_object_name, namelen);
obj->methods = method;
if (ubus_object_methods) {