[coreboot-gerrit] New patch to review for coreboot: 90bec3a romcc: Fix off-by-one

Patrick Georgi (patrick@georgi-clan.de) gerrit at coreboot.org
Fri Nov 15 22:27:34 CET 2013


Patrick Georgi (patrick at georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4089

-gerrit

commit 90bec3a3ba024e07f78081f6927d55e8ff98dae3
Author: Patrick Georgi <patrick at georgi-clan.de>
Date:   Mon Nov 11 15:57:09 2013 +0100

    romcc: Fix off-by-one
    
    Arrays are indexed 0..(number_of_element-1).
    
    Change-Id: I2157e74340568636d588113d1d2d8cae50082da2
    Found-by: Coverity Scan
    Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
 util/romcc/romcc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c
index 0c7c7e1..b045b46 100644
--- a/util/romcc/romcc.c
+++ b/util/romcc/romcc.c
@@ -898,7 +898,7 @@ static const char *tops(int index)
 	if (index < 0) {
 		return unknown;
 	}
-	if (index > OP_MAX) {
+	if (index >= OP_MAX) {
 		return unknown;
 	}
 	return table_ops[index].name;
@@ -10398,7 +10398,7 @@ static void simplify(struct compile_state *state, struct triple *ins)
 	do {
 		op = ins->op;
 		do_simplify = 0;
-		if ((op < 0) || (op > sizeof(table_simplify)/sizeof(table_simplify[0]))) {
+		if ((op < 0) || (op >= sizeof(table_simplify)/sizeof(table_simplify[0]))) {
 			do_simplify = 0;
 		}
 		else {



More information about the coreboot-gerrit mailing list