New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTF8 failure with sprintf () #9636
Comments
From hmbrand@cpan.orgCreated by hmbrand@cpan.org--8<--- demo.pl my $v = "\x{20ac} 12,345.00"; with Data::Peek for debugging: PV("\342\202\254 12,345.00"\0) [UTF8 "\x{20ac} 12,345.00"] without: panic: utf8_mg_pos_cache_update cache 12 real 11 for ? 12,345.00 at demo.pl line 9. Which is a crash. Perl Info
|
From @nwc10Dave notes: A panic in 5.10.0, maint, bleed; but not in 5.8.8 or 5.8.9 |
@nwc10 - Status changed from 'new' to 'open' |
From p5p@spam.wizbit.beOn Fri Jan 23 12:14:54 2009, hmbrand@cpan.org wrote:
Binary search: ----Program---- my $v = "\x{20ac} 12,345.00"; ----Output of .../p0IhoGv/perl-5.9.4@31245/bin/perl---- ----EOF ($?='0')---- ----EOF ($?='65280')---- http://public.activestate.com/cgi-bin/perlbrowse/p/31246 delete unused vars PL_av_fetch_sv, PL_hv_fetch_sv The only other difference I can find is that SvLEN is 14 on perl-5.8.7 Best regards, Bram |
From alex@chmrr.netAt Fri Jan 23 15:14:55 -0500 2009, hmbrand@cpan.org (via RT) wrote:
Attached is a fix for this. Unfortunately, I don't think we can get Thanks to Best Practical for volunteering my time to look at some of |
From alex@chmrr.net0001-Fix-RT-6266-sv_pos_u2b-expects-to-be-called-with-a-v.patchFrom dcba34fa03ca9da9b27871a19948cd516479c892 Mon Sep 17 00:00:00 2001
From: Alex Vandiver <alexmv@mit.edu>
Date: Fri, 29 May 2009 16:21:22 -0400
Subject: [PATCH] Fix [RT#6266] -- sv_pos_u2b expects to be called with a valid character index
sv_pos_u2b, when utf8 position caching is enabled, treats the uoffset
it is given as real, storing it away for lature use. sprintf, here,
passes the byte length of the string, which causes an invalid offset
to be cached.
---
sv.c | 5 +++--
t/op/sprintf2.t | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/sv.c b/sv.c
index a2fd856..a10bbf3 100644
--- a/sv.c
+++ b/sv.c
@@ -9444,7 +9444,8 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
if (DO_UTF8(argsv)) {
I32 old_precis = precis;
if (has_precis && precis < elen) {
- I32 p = precis;
+ I32 ulen = sv_len_utf8(argsv);
+ I32 p = precis > ulen ? ulen : precis;
sv_pos_u2b(argsv, &p, 0); /* sticks at end */
precis = p;
}
@@ -9459,7 +9460,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
}
string:
- if (has_precis && elen > precis)
+ if (has_precis && precis < elen)
elen = precis;
break;
diff --git a/t/op/sprintf2.t b/t/op/sprintf2.t
index 397c19e..765bf68 100644
--- a/t/op/sprintf2.t
+++ b/t/op/sprintf2.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 1295;
+plan tests => 1344;
is(
sprintf("%.40g ",0.01),
@@ -139,3 +139,19 @@ foreach my $n (2**1e100, -2**1e100, 2**1e100/2**1e100) { # +Inf, -Inf, NaN
eval { my $f = sprintf("%f", $n); };
is $@, "", "sprintf(\"%f\", $n)";
}
+
+# Check unicode vs byte length
+for my $width (1,2,3,4,5,6,7) {
+ for my $precis (1,2,3,4,5,6,7) {
+ my $v = "\x{20ac}\x{20ac}";
+ my $format = "%" . $width . "." . $precis . "s";
+ my $chars = ($precis > 2 ? 2 : $precis);
+ my $space = ($width < 2 ? 0 : $width - $chars);
+ fresh_perl_is(
+ 'my $v = "\x{20ac}\x{20ac}"; my $x = sprintf "'.$format.'", $v; $x =~ /^(\s*)(\S*)$/; print "$_" for map {length} $1, $2',
+ "$space$chars",
+ {},
+ q(sprintf ").$format.q(", "\x{20ac}\x{20ac}"),
+ );
+ }
+}
--
1.6.3.204.g8c948
|
@rgs - Status changed from 'open' to 'resolved' |
From @rgs2009/5/29 Alex Vandiver <alex@chmrr.net>:
Thanks, applied as 9ef5ed9.
Thanks indeed ! |
Migrated from rt.perl.org#62666 (status was 'resolved')
Searchable as RT62666$
The text was updated successfully, but these errors were encountered: