]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
env: Use static_assert() to check if default_environment is too large
authorMarek Behún <marek.behun@nic.cz>
Fri, 22 Oct 2021 13:47:25 +0000 (15:47 +0200)
committerSimon Glass <sjg@chromium.org>
Sun, 31 Oct 2021 18:26:44 +0000 (12:26 -0600)
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 <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
env/common.c
include/env_default.h

index 664d2e688ed5a6e0444db48b9cba46c8f87ce997..99729ca002c2d8696a22b30a060d938629b1b440 100644 (file)
@@ -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, "
index a6724719ecacceb263fa407dc29479bf2260d3d6..23430dc70d7fd12074f7c1b1280dc8036e5798e4 100644 (file)
@@ -121,3 +121,9 @@ const char default_environment[] = {
        }
 #endif
 };
+
+#if !defined(USE_HOSTCC) && !defined(DEFAULT_ENV_INSTANCE_EMBEDDED)
+#include <env_internal.h>
+static_assert(sizeof(default_environment) <= ENV_SIZE,
+             "Default environment is too large");
+#endif