Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50939C433FE for ; Thu, 13 Oct 2022 12:35:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5886884F41; Thu, 13 Oct 2022 14:32:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ouk4pudu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A8AB584F22; Thu, 13 Oct 2022 14:31:05 +0200 (CEST) Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7A27184F5A for ; Thu, 13 Oct 2022 14:30:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2a.google.com with SMTP id r142so1157242iod.11 for ; Thu, 13 Oct 2022 05:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=91ccO9Yn0Ddld9ahppitAua/jGGAEnvxC6Q7bGLRVes=; b=Ouk4pudu3pY0llLwgLoDgus7OiNn0QBs9A3ddmkfqHAiHde0N4OOPWItILNBTBfNUQ omE2lHDURzmlAVWZx4FOMi95zMztNvvWxKofWOrsSeVsCpwjlRS2ywe+3WcCLD2d2PId o7tKhGJ9bEiteuaiKfdXrNXKOUMlNr8c6zgvs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=91ccO9Yn0Ddld9ahppitAua/jGGAEnvxC6Q7bGLRVes=; b=Dw5qzNW7lSm2cZ9/9vhGZyIOh1B3ew1mjvBtXIXm6hyqCOBhYRjIYDmcQxJo5QOcRm iNQ/c3De7eKkLIDa8JyeK3gkM2eEWlinEGMEe7VFZartQyJuiNNSv1IsRroAN9avF8+Q p+ghrzPCVnb6CqswPLMeRIzkJeBRUco2MzTY0BP1+GmmbGPLBc1Ah3yOKXg1rYWtEh2z omqaM0DmdkcJhLKNlBPGofZFA5GUW5WmhoKyZkQfody8PuDqWDemRvcEGFAPYk4jEj3E StxvvmVG8vPicTyp4TfLt8+KJsnQx5CM/rcK0vM7BGSD/MhlVIt6FzETrPUHE7I18bKZ XlJQ== X-Gm-Message-State: ACrzQf11JDtb6DjZkLjPWq6GW7s44WlT27xwh5xCb11096N5U171grhZ WhbAmvL1b44rodm9ffolXDBC//AZT7cNkg== X-Google-Smtp-Source: AMsMyM5iSLKzeUvGwb3/10hTFko8WQpUxFsO0U/B4UJhCFg+HWGJ3yb1aYw2rIpYdQe99O02z/eoEw== X-Received: by 2002:a05:6638:d03:b0:363:efb2:41de with SMTP id q3-20020a0566380d0300b00363efb241demr2031158jaj.36.1665664238749; Thu, 13 Oct 2022 05:30:38 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id a9-20020a027a09000000b003635ab4a7b7sm7321626jac.3.2022.10.13.05.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:30:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Andre Przywara , Heinrich Schuchardt , Jan Kiszka , Joe Hershberger , Marek Vasut , Philippe Reynes , Sean Anderson Subject: [PATCH v2 29/45] image: Correct strncpy() warning with image_set_name() Date: Thu, 13 Oct 2022 06:29:11 -0600 Message-Id: <20221013122927.636867-30-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013122927.636867-1-sjg@chromium.org> References: <20221013122927.636867-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean gcc 12 seems to warn on strncpy() as a matter of course. Rewrite the code a different way to do the same thing, to avoid the warning. Signed-off-by: Simon Glass --- (no changes since v1) include/image.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/image.h b/include/image.h index 7c91e705bf1..a8fd3e34287 100644 --- a/include/image.h +++ b/include/image.h @@ -853,7 +853,13 @@ image_set_hdr_b(comp) /* image_set_comp */ static inline void image_set_name(struct legacy_img_hdr *hdr, const char *name) { - strncpy(image_get_name(hdr), name, IH_NMLEN); + /* + * This is equivalent to: strncpy(image_get_name(hdr), name, IH_NMLEN); + * + * Use the tortured code below to avoid a warning with gcc 12. We do not + * want to include a nul terminator if the name is of length IH_NMLEN + */ + memcpy(image_get_name(hdr), name, strnlen(name, IH_NMLEN)); } int image_check_hcrc(const struct legacy_img_hdr *hdr); -- 2.38.0.rc1.362.ged0d419d3c-goog