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>
master
Peter Hutterer 2021-03-29 16:23:28 +10:00 committed by Ran Benita
parent cda2eaf1f5
commit 20f7f80c23
1 changed files with 5 additions and 4 deletions

View File

@ -700,15 +700,16 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
str = xkb_atom_text(ctx, val); str = xkb_atom_text(ctx, val);
len = strlen(str); len = strlen(str);
if (len < 1 || len > 7) { if (len < 1 || len > sizeof(act->data)) {
log_warn(ctx, log_warn(ctx,
"A private action has 7 data bytes; " "A private action has %ld data bytes; "
"Illegal data ignored\n"); "Illegal data ignored\n", sizeof(act->data));
return false; return false;
} }
/* act->data may not be null-terminated, this is intentional */ /* 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; return true;
} }
else { else {