From: Lionel Sambuc Date: Tue, 8 Oct 2013 09:43:31 +0000 (+0200) Subject: Fix out of array bounds errors with -O3 X-Git-Tag: v3.3.0~762 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/migration-4to9?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F1014%2F1;p=minix.git Fix out of array bounds errors with -O3 When compiling with -O3 gcc seems to be a lot stricter on its checks for index out of bounds error. Change-Id: I5a63e1db6aa2375223ff13c6352643a9804fa93d --- diff --git a/lib/libcurses/copywin.c b/lib/libcurses/copywin.c index 0bec7224f..6db2b3bb8 100644 --- a/lib/libcurses/copywin.c +++ b/lib/libcurses/copywin.c @@ -118,7 +118,8 @@ int copywin(const WINDOW *srcwin, WINDOW *dstwin, cc.elements = 1; np = sp->nsp; if (np) { - while (np && cc.elements <= + /* MINIX: off-by one error, has to be strictly less than. */ + while (np && cc.elements < CURSES_CCHAR_MAX) { cc.vals[cc.elements++] = np->ch; np = np->next; diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 1dcedb434..62eaa0d57 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -454,7 +454,8 @@ parsedev(char *arg) if (*ep != '\0') mtree_err("invalid number `%s'", p); - if (argc > MAX_PACK_ARGS) + /* MINIX: 03 warns for above array bounds*/ + if (argc >= MAX_PACK_ARGS) mtree_err("too many arguments"); } if (argc < 2)