From 61a3fb803c3babf0e3e750430415338e6506a241 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 24 Jun 2012 03:47:39 -0500 Subject: [PATCH] add warning for negative argument to chr() [perl #83048] --- pp.c | 3 ++- t/uni/chr.t | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pp.c b/pp.c index 6936b4f..1fcc885 100644 --- a/pp.c +++ b/pp.c @@ -3262,7 +3262,8 @@ PP(pp_chr) if (IN_BYTES) { value = POPu; /* chr(-1) eq chr(0xff), etc. */ } else { - (void) POPs; /* Ignore the argument value. */ + SV *top = POPs; + Perl_ck_warner(aTHX_ packWARN(WARN_UTF8), "Invalid negative number (%"SVf") in chr", top); value = UNICODE_REPLACEMENT; } } else { diff --git a/t/uni/chr.t b/t/uni/chr.t index 33283e7..854d725 100644 --- a/t/uni/chr.t +++ b/t/uni/chr.t @@ -8,7 +8,7 @@ BEGIN { } use strict; -plan (tests => 6); +plan (tests => 8); use encoding 'johab'; ok(chr(0x7f) eq "\x7f"); @@ -19,4 +19,13 @@ for my $i (127, 128, 255) { ok(chr($i) eq pack('C', $i)); } +# [perl #83048] +{ + my $w; + local $SIG{__WARN__} = sub { $w .= $_[0] }; + my $chr = chr(-1); + is($chr, "\x{fffd}", "invalid values become REPLACEMENT CHARACTER"); + like($w, qr/^Invalid negative number \(-1\) in chr at /, "with a warning"); +} + __END__ -- 2.7.4