[RFC PATCH v2 12/17] lib: getopt: Tidy up two minor redundancies
Simon Glass
sjg at chromium.org
Wed May 20 01:31:38 CEST 2026
memcpy() already copies argv[argc] (the NULL terminator), so the
explicit gs->args[argc] = NULL after it does nothing. Drop it.
In the optional-argument branch, '*(curoptp + 1)' is already known
to be ':' by the preceding check, so the first half of the &&
is dead. Use curoptp[2] == ':' directly.
No functional change.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
lib/getopt.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/getopt.c b/lib/getopt.c
index 126427bb4ad..0179ae4d5ea 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -22,7 +22,6 @@ void getopt_init_state(struct getopt_state *gs, int argc, char *const argv[])
gs->argc = argc;
memcpy(gs->argv, argv, (argc + 1) * sizeof(*gs->argv));
- gs->argv[argc] = NULL;
gs->index = 1;
gs->arg_index = 1;
gs->nonopts = 0;
@@ -107,7 +106,7 @@ int __getopt(struct getopt_state *gs, const char *optstring, bool silent)
return curopt;
}
- if (*(curoptp + 1) && *(curoptp + 2) == ':') {
+ if (curoptp[2] == ':') {
/* optional argument */
if (argv[gs->index][gs->arg_index + 1]) {
/* optional argument with directly following arg */
--
2.43.0
More information about the U-Boot
mailing list