[PATCH 0/3] cmd: setexpr: add fmt format string operation
Marek Behún
marek.behun at nic.cz
Wed Jun 30 19:11:55 CEST 2021
On Wed, 30 Jun 2021 12:17:47 -0400
Sean Anderson <seanga2 at gmail.com> wrote:
> On 6/29/21 11:13 AM, Wolfgang Denk wrote:
> > Dear Sean,
> >
> > In message <19b6eeea-2aad-972b-aeeb-8959aab17d7a at gmail.com> you
> > wrote:
> >>
> >> The issue with this is twofold. First, there is no portable way to
> >> construct a va_list from C code. So the likely way to do this
> >> would be to set an arbitrary limit, and then just pass the
> >> arguments in. E.g. something like
> >
> > We already have an argument list: it's what's being passed to the
> > "setexpr" command, minus the initial arguments.
> >
> >> snprintf(buf, sizeof(buf), argv[3], argc >= 4 ? argv[4] :
> >> NULL, /* etc */);
> >
> > Why this test on argc? If it's less than 4, argv[4] should be NULL
> > anyway.
>
> snprintf(buf, sizeof(buf), argv[3], argc >= 4 ? argv[4] :
> NULL, argc >= 5 ? argv[5] : NULL, argc >= 6 ? argv[6] : NULL, /* etc
> */);
This is insane. The argv[]s are strings. What if I use "%08x" as format,
and pass "123" as argument?? It would print pointer to the string.
Clearly this needs its own implementation...
Marek
More information about the U-Boot
mailing list