Skip to content
Prev 32420 / 63424 Next

incorrect output and segfaults from sprintf with %*d (PR#13667)

maechler at stat.math.ethz.ch wrote:
hmm, i'd guess this limit is valid for all strings included in the
output with any format?  not just %s (and, as it appears, undocumentedly
%d)?
i didn't find the limit itself problematic.  (so far?)

btw. (i do know what that means ;)), after your recent fix:

    sprintf('%q%s', 1)
    # Error in sprintf("%q%s", 1) :
    #  use format %f, %e, %g or %a for numeric objects

    sprintf('%s', 1)
    # [1] "1"

you may want to add '%s' (and '%x', and ...) to the error message.  or
perhaps make it say sth like 'invalid format: ...'.  the problem is not
that %q is not applicable to numeric, but that it is not a valid format
at all.

there's also an issue with the additional arguments supplied after the
format:  any superfluous arguments are ignored (this is not documented,
as far as i can see), but they *are* evaluated nevertheless, e.g.:

    sprintf('%d', 0, {print(1)})
    # "1"
    # [1] "0"

it might be a good idea to document this behaviour.

best,
vQ

vQ