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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5ABFC433EF for ; Fri, 22 Oct 2021 13:57:39 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 160B961052 for ; Fri, 22 Oct 2021 13:57:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 160B961052 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 27B5683458; Fri, 22 Oct 2021 15:57:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="Bmal1Jc5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CB1A683270; Fri, 22 Oct 2021 15:57:35 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 13ECF8355C; Fri, 22 Oct 2021 15:47:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 4384A61205; Fri, 22 Oct 2021 13:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634910476; bh=b6ZT8dOD9iUUrHRYWvBy8SPg6jrBYsnC25NSCiUWWfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bmal1Jc5jqdEFfQJcS+gJzA1ElBYPJ3jLwf8n5nMhUCDcLG+MkMtZRl1skP5IDo7Y ogmn/ncEbuLv9fv4C/2Z0mTJh7/pf47UvS86+pq9j+fbm6bqvT3dzezJ9hVAMPfizn wgHtl2oDvs1Ts2m6oBvEijQStILF7MyIUhkyNtQr4iLJqxkUX2MeVL58hshOLGr1QD eKtqz/+fJgmJNzpXLc+KiEkSW1fGFdRMkKieiwndg/ljuSzUCvbyp1yecJmycGwEIk FE4OI5bemaqhR56BNO9MsTB4DaGD0sNw3lqJZCFeUyG+IjTHTsl6SJMhpw3RLeC55D sWuKXaHamaaKg== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: u-boot-board-maintainers@lists.denx.de, u-boot-custodians@lists.denx.de, Tom Rini , Simon Glass , u-boot@lists.denx.de, Joe Hershberger , Wolfgang Denk Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH 14/14] env: Use static_assert() to check if default_environment is too large Date: Fri, 22 Oct 2021 15:47:25 +0200 Message-Id: <20211022134725.26004-15-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211022134725.26004-1-kabel@kernel.org> References: <20211022134725.26004-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn Check sizeof(default_environment) against ENV_SIZE in a static_assert() instead of runtime. Only check if !USE_HOSTCC (for in fw_env tool ENV_SIZE expands to a variable, and cannot be checked statically) nad !DEFAULT_ENV_INSTANCE_EMBEDDED, for in that case the default_environment variable is not set. Signed-off-by: Marek BehĂșn --- env/common.c | 5 ----- include/env_default.h | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/env/common.c b/env/common.c index 664d2e688e..99729ca002 100644 --- a/env/common.c +++ b/env/common.c @@ -247,11 +247,6 @@ char *env_get_default(const char *name) void env_set_default(const char *s, int flags) { - if (sizeof(default_environment) > ENV_SIZE) { - puts("*** Error - default environment is too large\n\n"); - return; - } - if (s) { if ((flags & H_INTERACTIVE) == 0) { printf("*** Warning - %s, " diff --git a/include/env_default.h b/include/env_default.h index a6724719ec..23430dc70d 100644 --- a/include/env_default.h +++ b/include/env_default.h @@ -121,3 +121,9 @@ const char default_environment[] = { } #endif }; + +#if !defined(USE_HOSTCC) && !defined(DEFAULT_ENV_INSTANCE_EMBEDDED) +#include +static_assert(sizeof(default_environment) <= ENV_SIZE, + "Default environment is too large"); +#endif -- 2.32.0