This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sprintf(): handle mangled formats better with utf8
authorDavid Mitchell <davem@iabyn.com>
Wed, 10 May 2017 10:19:38 +0000 (11:19 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:00 +0000 (09:11 +0100)
commitc0535913148dc15651cf402b864ceb78a5e40c6d
tree12822af7a842bd426f17fc83a983a9f5064ad292
parent075f29f481ebf101b77740c973de022de650189d
sprintf(): handle mangled formats better with utf8

Currently if sprintf() detects an error in the format while processing
a %.... entry, it copies the bytes as-is from the % to the point the
error was detected, then continues, If the output string and format string
don't have the same utf8-ness, this can result in badly-formed utf8
output.

This commit changes the code so that it just appends a '%' then restarts
processing from the character following the %. Most of the time this just
again results with the characters following the % being output as-is,
expect this time the 'normal' character-copying code path is taken, which
handles utf8 mismatches correctly.

By doing this, it also removes a block of code which contained a "roll
your own" string appender which used SvGROW() and Copy(). This was one
further place which was potentially open to wrapping and block overrun
bugs.

This commit may cause occasional changes in behaviour, depending on
whether there are any further '%' characters within the bad section of the
format.  Now these will be reprocessed, possibly triggering further
'Invalid conversion' type warnings.
sv.c
t/op/sprintf.t
t/op/sprintf2.t