From patchwork Wed Dec 11 14:23:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1207683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uyR73f76"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Xzhk5X7Wz9sR8 for ; Thu, 12 Dec 2019 01:24:35 +1100 (AEDT) Received: from localhost ([::1]:43156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if2ul-0005Qb-DK for incoming@patchwork.ozlabs.org; Wed, 11 Dec 2019 09:24:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33505) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if2tt-0005Pc-HV for qemu-devel@nongnu.org; Wed, 11 Dec 2019 09:23:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1if2ts-0003B4-HF for qemu-devel@nongnu.org; Wed, 11 Dec 2019 09:23:37 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:51472) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1if2tr-00039Z-OJ; Wed, 11 Dec 2019 09:23:36 -0500 Received: by mail-wm1-x343.google.com with SMTP id d73so4024558wmd.1; Wed, 11 Dec 2019 06:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ItNU5Cjsmx9/ZsYgHNT2cDFny7KJ3p+tyVmczFqGZzE=; b=uyR73f76FVa5KGA9y+QE9Uwzx+MzayFIGbUIW+v7rFJXVm/n3CqqUZFs5FANDmCAd3 0yXWZqYvQyz6Krt0eidLNMJ4Ekbd+8Kgt7WY2fZASVlloalP11+F0Rf5dgRp5kMmdl4D qdL63e4KcK5nG0YaGtRz35qLHJsMPzoKG5gbr3lcSu7gai4LTsDVGO1Mx+afX2BD6rXw ynEqcW6AxPxLWGg8hI5Y1//+YIZnQ5Mf0TS3qqYmzoHEUyERg9ecbxWWYb7dn7gCau9w HOQyPN3827vMVFFwyTCQTOqU4gs/AcbAX3cS29jAqxNk6DQ6K8rKfQ6jipUvsCNlBlfN SImw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=ItNU5Cjsmx9/ZsYgHNT2cDFny7KJ3p+tyVmczFqGZzE=; b=Ig5RYeO3EGdNKKYYQvCtd4+fIZJVBqFxAiMW7HG803DriAh6g7P1L79apjDH1QK3Ck OUvw65S4Rcn+VoSn7Fb26TrCE08wKQanjmsfvfS3MEBaC/6xMv+B7sKyQWCxMcOn7Tbp MYNRYXcM8jNYpVNNODvNSIaYNiupeimdgEEvWu0hp/UwzdwXfLjbn8vSFx7kHTa47tj3 V4TbPzb+fbeQRWzzvQXFSQ1JizZIzsigVma1iuO4Nr9aC99v68z5zuiA99D2al9thVU8 6rJHV871fdt923gI3CvZVJlGyubyrlUoli/J4pEKcn7mG9wjWrljlIbu2IJCPTggQHwY ZxMA== X-Gm-Message-State: APjAAAWMS41u91GDsfVyn38rogF1xOMJobqkRf4KLVJkFz60a6uUUY2T FICfZCX6z1hbOuC1/SxqWxur0K/J X-Google-Smtp-Source: APXvYqzPnZmUwzo8FupmKWZH/cLnaT2m6s32BE39/euS7agIVRnZH9ACqBLzWrDWJ1P05SadDtb/kQ== X-Received: by 2002:a1c:f003:: with SMTP id a3mr33629wmb.41.1576074214465; Wed, 11 Dec 2019 06:23:34 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id g23sm2503783wmk.14.2019.12.11.06.23.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2019 06:23:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH] migration: fix stringop-truncation warning Date: Wed, 11 Dec 2019 15:23:24 +0100 Message-Id: <1576074210-52834-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau ../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 Signed-off-by: Paolo Bonzini --- 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)