From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP7x9-00044g-6t for qemu-devel@nongnu.org; Tue, 20 Nov 2018 10:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gP7x5-0005EM-8d for qemu-devel@nongnu.org; Tue, 20 Nov 2018 10:28:39 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 20 Nov 2018 19:27:52 +0400 Message-Id: <20181120152753.10463-3-marcandre.lureau@redhat.com> In-Reply-To: <20181120152753.10463-1-marcandre.lureau@redhat.com> References: <20181120152753.10463-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-3.1? 2/3] migration: fix stringop-truncation warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Juan Quintela , Max Reitz , Jeff Cody , Liu Yuan , Igor Mammedov , "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Adding an assert is enough to silence GCC. ~/src/qemu/migration/global_state.c: In function 'global_state_store_runn= ing': ~/src/qemu/migration/global_state.c:45:5: error: 'strncpy' specified boun= d 100 equals destination size [-Werror=3Dstringop-truncation] strncpy((char *)global_state.runstate, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ state, sizeof(global_state.runstate)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors (alternatively, we could hard-code "running") Signed-off-by: Marc-Andr=C3=A9 Lureau --- migration/global_state.c | 1 + 1 file changed, 1 insertion(+) diff --git a/migration/global_state.c b/migration/global_state.c index 8e8ab5c51e..01805c567a 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -42,6 +42,7 @@ int global_state_store(void) void global_state_store_running(void) { const char *state =3D RunState_str(RUN_STATE_RUNNING); + assert(strlen(state) < sizeof(global_state.runstate)); strncpy((char *)global_state.runstate, state, sizeof(global_state.runstate)); } --=20 2.19.1.708.g4ede3d42df