Enhances code clarity by utilizing USTATE_MAX in place of hard-coded values. This makes it easier to find usages of ustate when grepping the code. Also, it's more robust and can handle additional ustates without further modification.
Signed-off-by: Michael Adler <[email protected]> --- tools/bg_setenv.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c index f318f12..be4db5c 100644 --- a/tools/bg_setenv.c +++ b/tools/bg_setenv.c @@ -209,13 +209,15 @@ static error_t parse_setenv_opt(int key, char *arg, struct argp_state *state) return 1; } } - if (i < 0 || i > 3) { + if (i < 0 || i >= USTATE_MAX) { fprintf(stderr, "Invalid ustate value specified. Possible " - "values: " - "0 (%s), 1 (%s), 2 (%s), 3 (%s)\n", - ustate2str(0), ustate2str(1), ustate2str(2), - ustate2str(3)); + "values: "); + for (int j = 0; j < USTATE_MAX; j++) { + fprintf(stderr, "%d (%s)%s", j, + ustate2str(j), + j < USTATE_MAX - 1 ? ", " : "\n"); + } return 1; } else { res = asprintf(&tmp, "%u", i); -- 2.41.0 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20230726084349.43783-1-michael.adler%40siemens.com.
