[Toybox] [PATCH] Make yesno printf-like.

enh enh at google.com
Wed Sep 2 08:09:13 PDT 2015


On Tue, Sep 1, 2015 at 11:26 PM, Rob Landley <rob at landley.net> wrote:
> On 09/01/2015 08:35 PM, enh wrote:
>> Make yesno printf-like.
>
> This just makes me uncomfortable that it's nonobvious enough somebody's
> going to yesno(1, usersupplieddata);.

that seems unlikely, especially given that yesno doesn't supply the
"?". (and you really ought to get out of the habit of being so tricky
at the cost of readability all the time anyway!)

btw, though this distracts from my point and will probably only
encourage you to stick with the status quo... toybox already blindly
uses user-supplied strings as format strings. random example:

$ seq -f '%s' 1 3
seq: format ‘%s’ has unknown %s directive

$ ./toybox seq -f '%s' 1 3
Segmentation fault (core dumped)

the compiler will find these for you with -Wformat-nonliteral (but for
cases like this where you do need to use user-supplied input and just
need to sanitize it first, there's no clean way to silence the warning
when you're done; i guess we could add an fprintf_unsafe and rely on
human code review to prevent inappropriate use [which would leave us
no worse off than we are today]).

> You never reprompt for yesno so printing arbitrarily complex prompt
> could be the caller's job. That was intentional.

but yesno does output the "(y/N)" part, so i'm not sure what you gain
from this. do you have an example where this is needed?

>> In addition to making most existing code slightly simpler, this will
>> let us move "if (!isatty(0)) return def;" into yesno so we can avoid
>> printing a prompt in non-interactive situations.
>
> Except you don't want to do that without a flag of its own:
>
> $ cp -a lib bloit
> $ cat | rm -ri bloit | cat
> rm: descend into directory ‘bloit’? y
> rm: remove regular file ‘bloit/help.c’? y
>
> That's the ubuntu implementation, not mine, so if it's wrong it's at
> least definitively wrong. :) Suppressing the prompt has to be done on a
> per-case basis.
>
> Let me think about it a bit...
>
> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.

 1441206553.0


More information about the Toybox mailing list