Subject: Re: bug#73068: printf: please implement POSIX:2024 argument reordering

From: Collin Funk <[email-masked]>
Date: Thu, 12 Sep 2024 10:40:48 -0700

Hi Pádraig,

Pádraig Brady <[email-masked]> writes:

> I'll apply the attached sometime tomorrow.
>
> Marking this as done.

Patch looks good, thanks.

One small comment, though.

> +#define GET_CURR_ARG(POS)				\
> +do {							\
> +  char *arge;						\
> +  intmax_t arg = POS==3 ? 0 : strtoimax (f, &arge, 10);	\
> +  if (0 < arg && arg <= INT_MAX && *arge == '$')	\
> +    /* Process indexed %i$ format.  */			\
> +    /* Note '$' comes before any flags.  */		\

Shouldn't you check errno here, like:

  char *arge;
  errno = 0;
  intmax_t arg = POS==3 ? 0 : strtoimax (f, &arge, 10);
  if (errno == 0 && 0 < arg && arg <= INT_MAX && *arge == '$')
  [...]

I think that would handle all bad cases.

For example, I think "%$" might return 0 but set errno to EINVAL.

Collin