From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH] migration: fix stringop-truncation warning
Date: Wed, 11 Dec 2019 15:23:24 +0100 [thread overview]
Message-ID: <1576074210-52834-3-git-send-email-pbonzini@redhat.com> (raw)
From: Marc-André Lureau <marcandre.lureau@redhat.com>
../migration/global_state.c: In function ‘global_state_store_running’:
../migration/global_state.c:47:5: error: ‘strncpy’ specified bound 100 equals destination size [-Werror=stringop-truncation]
47 | strncpy((char *)global_state.runstate,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48 | state, sizeof(global_state.runstate));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The assert() above allows to call with strlen(src)+1.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
migration/global_state.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/migration/global_state.c b/migration/global_state.c
index 2531147..a39a876 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -44,8 +44,7 @@ void global_state_store_running(void)
{
const char *state = RunState_str(RUN_STATE_RUNNING);
assert(strlen(state) < sizeof(global_state.runstate));
- strncpy((char *)global_state.runstate,
- state, sizeof(global_state.runstate));
+ memcpy(global_state.runstate, state, strlen(state) + 1);
}
bool global_state_received(void)
--
1.8.3.1
next reply other threads:[~2019-12-11 14:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 14:23 Paolo Bonzini [this message]
2019-12-12 0:55 ` [PATCH] migration: fix stringop-truncation warning Richard Henderson
2019-12-12 1:06 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1576074210-52834-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).