From 1ff60178a90cab2a43a818a45bbc40e4389fd66c Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Sun, 28 Mar 2021 21:02:13 +0200 Subject: libpayload: curses: Only call `serial_set_color()` with initialized values Building nvramcui with i386-elf-gcc (coreboot toolchain v2021-04-06_7014f8258e) 8.3.0 and Link Time Optimization (LTO) enabled in libpayload (`CONFIG_LP_LTO=y`) fails with the error below. LPGCC nvramcui.bin curses/PDCurses/pdcurses/refresh.c: In function 'wrefresh': curses/pdcurses-backend/pdcdisp.c:217:4: error: 'bg' may be used uninitialized in this function [-Werror=maybe-uninitialized] curses/pdcurses-backend/pdcdisp.c:214:18: note: 'bg' was declared here curses/pdcurses-backend/pdcdisp.c:217:4: error: 'fg' may be used uninitialized in this function [-Werror=maybe-uninitialized] curses/pdcurses-backend/pdcdisp.c:214:14: note: 'fg' was declared here lto1: all warnings being treated as errors lto-wrapper: fatal error: i386-elf-gcc returned 1 exit status compilation terminated. /opt/xgcc/lib/gcc/i386-elf/8.3.0/../../../../i386-elf/bin/ld.bfd: error: lto-wrapper failed collect2: error: ld returned 1 exit status `pair_content()` returns in case `PAIR_NUMBER(attr)` is invalid, so guard the usage of `serial_set_color()`. if (pair < 0 || pair >= COLOR_PAIRS || !fg || !bg) return ERR; Note, building with x86_64-linux-gnu-gcc-10 (Debian 10.2.1-6) 10.2.1 20210110 does *not* fail. Change-Id: Ic63e34f2b5bc9f826db37597bebc6b20542481d7 Signed-off-by: Paul Menzel Reviewed-on: https://review.coreboot.org/c/coreboot/+/51914 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons --- payloads/libpayload/curses/pdcurses-backend/pdcdisp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'payloads/libpayload/curses/pdcurses-backend/pdcdisp.c') diff --git a/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c b/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c index 234d62a84b..2d05f43767 100644 --- a/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c +++ b/payloads/libpayload/curses/pdcurses-backend/pdcdisp.c @@ -212,9 +212,8 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) if (serial_cur_pair != PAIR_NUMBER(attr)) { short int fg, bg; - pair_content(PAIR_NUMBER(attr), - &fg, &bg); - serial_set_color(fg, bg); + if (pair_content(PAIR_NUMBER(attr), &fg, &bg) == OK) + serial_set_color(fg, bg); serial_cur_pair = PAIR_NUMBER(attr); } -- cgit v1.2.3