Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: sh emulation POSIX non-conformances (printf %10s and bytes vs character)



On 2021-04-22 12:22:12 -0700, Bart Schaefer wrote:
> On Thu, Apr 22, 2021 at 7:01 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > > POSIX requires:
> > >
> > > | Stéphane|
> > > |  Chazelas|
> >
> > I would think that's intentional, at least for the precision
> > (e.g. %.4s) in order to prevent buffer overflow.
> 
> That makes sense for C-ish languages, but I would think it was a bad
> idea in general for the shell to allocate buffer sizes based on user
> input.
> 
> Someone can probably point to the rationale document, but I'm guessing
> this is really because of equivalence with sprintf() formats.

Some file formats have fields with a byte-size limit. Providing
more than this limit could have unexpected effects. One may also
want to limit the size of generated filenames (see NAME_MAX).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




Messages sorted by: Reverse Date, Date, Thread, Author