Files
Philippe Mathieu-Daudé c4c07cac75 util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
Many functions map an enum or exception number to a name, either
with a switch statement or by indexing a string table after an
open-coded bounds check. Add STR_ARRAY_ELEM_OR_NULL(array, index),
which returns array[index], or NULL when index is out of bounds,
so such code can use a static table and a single call.

The array is passed as 'const char *const *', so only arrays of
strings are accepted; hence the STR_ prefix rather than a generic
name.

Misuse is caught at build time:
- pointer instead of array: "negative width in bit-field" error,
  plus -Wsizeof-pointer-div (GCC);
- array of non-strings (int[], char[][N], int *[]):
  -Wincompatible-pointer-types;
- array of non-const 'char *': -Wincompatible-pointer-types (GCC),
  -Wincompatible-pointer-types-discards-qualifiers (clang);
- pointer as index: -Wint-conversion.

Suggested-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Message-ID: <20261022215115.19680-3-philmd@oss.qualcomm.com>
2026-10-24 11:48:29 +02:00
..
2023-03-20 12:43:50 +01:00
2023-12-19 19:03:38 +01:00
2026-04-29 11:41:00 +10:00
2026-04-29 11:41:00 +10:00
2026-04-22 12:51:51 +04:00
2020-01-06 18:41:32 +04:00
2025-10-01 08:33:24 +02:00
2025-03-10 17:07:16 +08:00
2025-01-29 11:43:04 -03:00
2023-04-24 11:29:00 +02:00
2020-12-10 17:16:44 +01:00
2026-04-23 12:27:27 +02:00
2023-08-31 19:47:43 +02:00
2023-03-28 15:23:10 -07:00
2023-11-15 12:06:05 +03:00
2026-04-22 12:51:51 +04:00
2018-08-24 20:26:37 +02:00
2023-11-03 09:20:31 +01:00