mesa: test index bounds before array element

Check whether the index is within bounds before accessing the array.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Roel Kluin
2010-01-06 08:27:42 -08:00
committed by Brian Paul
parent 5db710a823
commit 324568f79d
3 changed files with 3 additions and 3 deletions

View File

@@ -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] = '-';
}

View File

@@ -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')

View File

@@ -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;