argp: Fix shift bug

From gnulib commits 06094e390b0 and 88033d3779362a.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
This commit is contained in:
Adhemerval Zanella 2025-05-07 11:17:28 -03:00
parent 7c00a20397
commit 1642570563
1 changed files with 9 additions and 6 deletions

View File

@ -735,12 +735,15 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
} }
} }
else else
/* A long option. We use shifts instead of masking for extracting /* A long option. Preserve the sign in the user key, without
the user value in order to preserve the sign. */ invoking undefined behavior. Assume two's complement. */
err = {
group_parse (&parser->groups[group_key - 1], &parser->state, int user_key =
(opt << GROUP_BITS) >> GROUP_BITS, ((opt & (1 << (USER_BITS - 1))) ? ~USER_MASK : 0) | (opt & USER_MASK);
parser->opt_data.optarg); err =
group_parse (&parser->groups[group_key - 1], &parser->state,
user_key, parser->opt_data.optarg);
}
if (err == EBADKEY) if (err == EBADKEY)
/* At least currently, an option not recognized is an error in the /* At least currently, an option not recognized is an error in the