i965: quieten compiler warning about out-of-bounds access
authorIlia Mirkin <imirkin@alum.mit.edu>
Tue, 5 Jan 2016 04:28:52 +0000 (23:28 -0500)
committerIlia Mirkin <imirkin@alum.mit.edu>
Tue, 5 Jan 2016 17:07:53 +0000 (12:07 -0500)
gcc 4.9.3 shows the following error:

brw_vue_map.c:260:20: warning: array subscript is above array bounds
[-Warray-bounds]
    return brw_names[slot - VARYING_SLOT_MAX];

This is because BRW_VARYING_SLOT_COUNT is a valid value for the enum
type. Adding an assert will generate no additional code but will teach
the compiler to not complain.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Timothy Arceri <timothy.arceri@collabora.com>
src/mesa/drivers/dri/i965/brw_vue_map.c

index 09eadbcb54fab1887e4768c0ac965b65b3c5863b..fea24368e8c4f8beaf841986724de046d9adeec2 100644 (file)
@@ -257,6 +257,7 @@ varying_name(brw_varying_slot slot)
       [BRW_VARYING_SLOT_PNTC - VARYING_SLOT_MAX] = "BRW_VARYING_SLOT_PNTC",
    };
 
+   assert(slot < BRW_VARYING_SLOT_COUNT);
    return brw_names[slot - VARYING_SLOT_MAX];
 }