Re: [PATCH v2 4/5] parse-options: introduce `OPTION_UNSIGNED`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 15, 2025 at 07:38:04PM +0200, René Scharfe wrote:
> Am 15.04.25 um 14:14 schrieb Patrick Steinhardt:
> > diff --git a/parse-options.c b/parse-options.c
> > index ae836c384c7..9670e46a679 100644
> > --- a/parse-options.c
> > +++ b/parse-options.c
> > @@ -216,6 +216,49 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
> >  			    optname(opt, flags));
> >  		}
> >  	}
> > +	case OPTION_UNSIGNED:
> > +	{
> > +		uintmax_t upper_bound = UINTMAX_MAX >> (bitsizeof(uintmax_t) - CHAR_BIT * opt->precision);
> > +		uintmax_t value;
> > +
> > +		if (unset) {
> > +			value = 0;
> > +		} else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
> > +			value = opt->defval;
> > +		} else if (get_arg(p, opt, flags, &arg)) {
> > +			return -1;
> > +		} else if (!*arg) {
> > +			return error(_("%s expects a numerical value"),
> > +				     optname(opt, flags));
> > +		} else {
> > +			value = strtoumax(arg, (char **)&s, 10);
> > +			if (*s)
> > +				return error(_("%s expects a numerical value"),
> > +					     optname(opt, flags));
> > +		}
> > +
> > +		if (value > upper_bound)
> > +			return error(_("value %"PRIuMAX" for %s exceeds %"PRIuMAX),
> > +				     value, optname(opt, flags), upper_bound);
> > +
> > +		switch (opt->precision) {
> > +		case 1:
> > +			*(int8_t *)opt->value = value;
> 
> uint8_t, surely.  Similarly for the other casts below.

Oof, of course.

Patrick




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux