intel/compiler: Handle invalid inputs to brw_reg_type_to_*()
authorMatt Turner <mattst88@gmail.com>
Thu, 2 Jan 2020 22:57:56 +0000 (14:57 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 22 Jan 2020 00:19:21 +0000 (00:19 +0000)
Necessary to handle these cases when we test fuzzed instructions.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2635>

src/intel/compiler/brw_reg_type.c

index 7a42f2ffbe6f94df12b25cd200a3d8145444a10b..c720542e3a0e9b381dc2a65733733a696a1f9640 100644 (file)
@@ -479,6 +479,9 @@ brw_reg_type_to_size(enum brw_reg_type type)
       [BRW_REGISTER_TYPE_V]  = 2,
       [BRW_REGISTER_TYPE_UV] = 2,
    };
+   if (type >= ARRAY_SIZE(type_size))
+      return -1;
+
    return type_size[type];
 }
 
@@ -509,6 +512,9 @@ brw_reg_type_to_letters(enum brw_reg_type type)
       [BRW_REGISTER_TYPE_V]  = "V",
       [BRW_REGISTER_TYPE_UV] = "UV",
    };
+   if (type >= ARRAY_SIZE(letters))
+      return "INVALID";
+
    assert(type < ARRAY_SIZE(letters));
    return letters[type];
 }