From 324568f79d6e014900c981bd9a0e1dffedc326c8 Mon Sep 17 00:00:00 2001 From: Roel Kluin Date: Wed, 6 Jan 2010 08:27:42 -0800 Subject: [PATCH] mesa: test index bounds before array element Check whether the index is within bounds before accessing the array. Signed-off-by: Roel Kluin Signed-off-by: Brian Paul --- src/mesa/drivers/dri/tdfx/tdfx_dd.c | 2 +- src/mesa/shader/nvfragparse.c | 2 +- src/mesa/shader/prog_optimize.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/dri/tdfx/tdfx_dd.c b/src/mesa/drivers/dri/tdfx/tdfx_dd.c index 8472df607ae..ed8a3315492 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_dd.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_dd.c @@ -91,7 +91,7 @@ static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name ) else { /* unexpected result: replace spaces with hyphens */ int i; - for (i = 0; hardware[i] && (i < sizeof(hardware)); i++) { + for (i = 0; i < sizeof(hardware) && hardware[i]; i++) { if (hardware[i] == ' ' || hardware[i] == '\t') { hardware[i] = '-'; } diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index b739a6aa07c..8ee7c930626 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -642,7 +642,7 @@ Parse_SwizzleSuffix(const GLubyte *token, GLuint swizzle[4]) else { /* 4-component swizzle (vector) */ GLint k; - for (k = 0; token[k] && k < 4; k++) { + for (k = 0; k < 4 && token[k]; k++) { if (token[k] == 'x') swizzle[k] = 0; else if (token[k] == 'y') diff --git a/src/mesa/shader/prog_optimize.c b/src/mesa/shader/prog_optimize.c index 4fe351251e8..8b9466a5a61 100644 --- a/src/mesa/shader/prog_optimize.c +++ b/src/mesa/shader/prog_optimize.c @@ -578,7 +578,7 @@ _mesa_remove_extra_moves(struct gl_program *prog) /* get pointer to previous instruction */ prevI = i - 1; - while (removeInst[prevI] && prevI > 0) + while (prevI > 0 && removeInst[prevI]) prevI--; prevInst = prog->Instructions + prevI; -- 2.30.2