From mboxrd@z Thu Jan 1 00:00:00 1970 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 E9522C04A95 for ; Sun, 25 Sep 2022 15:09:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 28AE384DAA; Sun, 25 Sep 2022 17:04:56 +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="oN8KbJmB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A688E84B0C; Sun, 25 Sep 2022 17:03:59 +0200 (CEST) Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) (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 19B41848C2 for ; Sun, 25 Sep 2022 17:03:57 +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-xd2c.google.com with SMTP id y141so3432477iof.5 for ; Sun, 25 Sep 2022 08:03:57 -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; bh=pL4F6+U/0hQoIRQxiVykuWawgAiU8DGpBf7lAEH8ZcQ=; b=oN8KbJmBzVM4BJcN87bKJlHp20IUl3bRDYnJyQ8FvwwhVQptD/ASRZz8D8wXh6HkQS +lwd1vsA6S80wJVHEwsnhuW/juoQZuWrUXpiHSxpMX6+PsJgcJFeQkLSjSoO9OnjoWnA tOrip0/wDlYG24bXjEoygjzEYPF04OWwB+i8M= 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; bh=pL4F6+U/0hQoIRQxiVykuWawgAiU8DGpBf7lAEH8ZcQ=; b=TSS0TFt3HifJkMtyoPHTUAVKU8LG6MQEMQ1iRa/FRuBSsfC8byaK7Vc5b6b+GuKd/g W+zIyO8ib/O7gbmLhschLsH7jEbdFkdPt1tnb+BApbXZ3Og9MllgttU7icnphV1gtvaq Ix2sCss5hR12B20Xoq7PxJjSLwmovx/9KX/hYdPxekuNEQRDgvNuxAXK7XsaE6WDOzdi 6eHfgl4NMznpduLZfDchLazIeEuFMjkPfSBPMsXYYvv0sX/gjl1nzKp54Xk3+/888Au9 RfARmnQ+cw8QOUzZ8oG69JSI7l1/8WLTtbw8oxoQ46lzalUDKZ9dmFtN+jcOkse1mFFg Yagg== X-Gm-Message-State: ACrzQf3teo3MvWV249IJLxctBhip9epihbIPRNjMFIUeiCH/N8x0C6TT cufo3wDUnpX7qcvHbUGMQAFgEtRFwyGg7w== X-Google-Smtp-Source: AMsMyM4g6TMQgBOMzLRYOv80tBJbQh4zdXZLrDvb8I4CYP90DslcXAGp4slhAt7oeDlQNGqHB6h9fA== X-Received: by 2002:a05:6638:3710:b0:35a:9470:bb31 with SMTP id k16-20020a056638371000b0035a9470bb31mr9282140jav.283.1664118220118; Sun, 25 Sep 2022 08:03:40 -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 u19-20020a926013000000b002f19d9838c6sm5360578ilb.25.2022.09.25.08.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 08:03:39 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alexandru Gagniuc , Andre Przywara , Heinrich Schuchardt , Jan Kiszka , Joe Hershberger , Marek Vasut , Philippe Reynes Subject: [PATCH 28/45] image: Correct strncpy() warning with image_set_name() Date: Sun, 25 Sep 2022 09:02:31 -0600 Message-Id: <20220925150248.2524421-29-sjg@chromium.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org> References: <20220925150248.2524421-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 --- include/image.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/image.h b/include/image.h index 2aef364e836..feb8e90c2e8 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.37.3.998.g577e59143f-goog