[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] migration: fix stringop-truncation warning
From: |
Paolo Bonzini |
Subject: |
[PATCH] migration: fix stringop-truncation warning |
Date: |
Wed, 11 Dec 2019 15:23:24 +0100 |
From: Marc-André Lureau <address@hidden>
../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 <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
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
- [PATCH] migration: fix stringop-truncation warning,
Paolo Bonzini <=