From 899a5d38fd1126cc0f1fb4ccfb196b6081262bb5 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Tue, 13 Dec 2016 15:47:22 +0100 Subject: [PATCH] libpayload/.../PDCurses: avoid reading orig before NULL checking it Coverity complains and that (unfortunately) means that some compiler might take advantage of the same fact. Change-Id: I59aff77820c524fa5a0fcb251c1268da475101fb Signed-off-by: Patrick Georgi Found-by: Coverity Scan #1261105 Reviewed-on: https://review.coreboot.org/17835 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth Signed-off-by: Patrick Georgi --- pdcurses/window.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pdcurses/window.c b/pdcurses/window.c index 129de5b0..4320e641 100644 --- a/pdcurses/window.c +++ b/pdcurses/window.c @@ -306,9 +306,7 @@ int mvwin(WINDOW *win, int y, int x) WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) { WINDOW *win; - int i; - int j = begy - orig->_begy; - int k = begx - orig->_begx; + int i, j, k; PDC_LOG(("subwin() - called: lines %d cols %d begy %d begx %d\n", nlines, ncols, begy, begx)); @@ -320,6 +318,9 @@ WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) (begx + ncols) > (orig->_begx + orig->_maxx)) return (WINDOW *)NULL; + j = begy - orig->_begy; + k = begx - orig->_begx; + if (!nlines) nlines = orig->_maxy - 1 - j; if (!ncols)