diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-29 16:23:28 +1000 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2021-03-30 01:34:33 +0300 |
commit | 20f7f80c236d63d5b6016fca838b2da19c220cd9 (patch) | |
tree | 62bb6a3ec804bab225ade6473897c21b55a18d9a | |
parent | cda2eaf1f5a021dd5d6876f233a1160f7dddd51c (diff) | |
download | xorg-lib-libxkbcommon-20f7f80c236d63d5b6016fca838b2da19c220cd9.tar.gz |
xkbcomp: use memcpy over strncpy to avoid analyzer warnings
The target buffer is 7 bytes long, null-termination is optional (as the comment
already suggests). Coverity is unhappy about this though so let's use memset and
memcpy instead.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/xkbcomp/action.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 605f159..e2d4c40 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -700,15 +700,16 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods, str = xkb_atom_text(ctx, val); len = strlen(str); - if (len < 1 || len > 7) { + if (len < 1 || len > sizeof(act->data)) { log_warn(ctx, - "A private action has 7 data bytes; " - "Illegal data ignored\n"); + "A private action has %ld data bytes; " + "Illegal data ignored\n", sizeof(act->data)); return false; } /* act->data may not be null-terminated, this is intentional */ - strncpy((char *) act->data, str, sizeof(act->data)); + memset(act->data, 0, sizeof(act->data)); + memcpy(act->data, str, len); return true; } else { |