From a4056238da1d6bc6327b8d090845db9a44fe5f34 Mon Sep 17 00:00:00 2001 From: Jeremy Bettis Date: Mon, 20 Sep 2021 16:08:14 -0600 Subject: ec: Fail on uninitialized variables The zephyr toolchain has -Werror=maybe-uninitialized enabled by default, so enable it for all gcc EC builds to prevent possible uninitialized vars from sneaking into the codebase. For clang builds, use -Werror=uninitialized instead. BRANCH=None BUG=None TEST=in docker: make -j CRYPTOC_DIR="${MODULES_DIR}/cryptoc" \ FTDIVERSION=1 HOSTGCOV='gcov' \ CROSS_COMPILE_arm=/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi- \ coverage in chroot; make try_build_boards buildall_only Change-Id: I3efb4b2958f2037606195743d768870e1d0b18b9 Signed-off-by: Jeremy Bettis Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3171939 Tested-by: Jeremy Bettis Auto-Submit: Jeremy Bettis Commit-Queue: Jack Rosenthal Reviewed-by: Jack Rosenthal --- Makefile.toolchain | 6 ++++++ test/vpd_api.c | 4 ++-- util/genvif.c | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile.toolchain b/Makefile.toolchain index e39a1c3016..29e0beca08 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -52,6 +52,12 @@ C_WARN = -Wstrict-prototypes -Wdeclaration-after-statement -Wno-pointer-sign COMMON_WARN = -Wall -Wundef -Werror -Werror-implicit-function-declaration \ -Wno-trigraphs -Wno-format-security -Wno-address-of-packed-member \ -fno-common -fno-strict-aliasing -fno-strict-overflow +ifeq ($(cc-name),clang) +COMMON_WARN+=-Werror=uninitialized +endif +ifeq ($(cc-name),gcc) +COMMON_WARN+=-Werror=maybe-uninitialized +endif UBSAN_FLAGS=-fsanitize=array-bounds,vla-bound \ -fno-sanitize=vptr \ diff --git a/test/vpd_api.c b/test/vpd_api.c index 960c0c664b..65e86adb96 100644 --- a/test/vpd_api.c +++ b/test/vpd_api.c @@ -324,8 +324,8 @@ void vpd_ct_set_pull(int pull, int rp_value) void vpd_ct_get_cc(int *cc1, int *cc2) { - int cc1_v; - int cc2_v; + int cc1_v = 0; + int cc2_v = 0; switch (ct_cc_pull) { case TYPEC_CC_RP: diff --git a/util/genvif.c b/util/genvif.c index a8b7f24ec4..6722df9349 100644 --- a/util/genvif.c +++ b/util/genvif.c @@ -2791,7 +2791,7 @@ static void init_vif_component_general_pd_fields( * to NO, then this field shall be set to YES. */ { - bool supports_to_dfp; + bool supports_to_dfp = false; switch (type) { case SRC: @@ -2833,7 +2833,7 @@ static void init_vif_component_general_pd_fields( * 5 (eMarker) then this field shall be ignored by Testers. */ { - bool supports_to_ufp; + bool supports_to_ufp = false; switch (type) { case SRC: -- cgit v1.2.1