diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2014-08-27 08:13:02 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2014-08-27 18:21:40 -0400 |
commit | 1f4ef0f182b07bd3c970ed636971821c8f754668 (patch) | |
tree | 185d48e0e37c73c0b473cbe27baf14d7bcb55d74 /pp_pack.c | |
parent | 1cd88304d705aae8d2b32c6e925fedd52980a122 (diff) | |
download | perl-1f4ef0f182b07bd3c970ed636971821c8f754668.tar.gz |
pack c/C on inf/nan.
Made them return the 0xFF byte (and warn). Not necessarily the best
choice, but there's not that much room in just 256 bytes for all of
the inf/-inf/nan. This same choice will need to be made with wider
integer packs.
Diffstat (limited to 'pp_pack.c')
-rw-r--r-- | pp_pack.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -2540,7 +2540,15 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) while (len-- > 0) { IV aiv; fromstr = NEXTFROM; - aiv = SvIV(fromstr); + if (SvNOK(fromstr) && Perl_isinfnan(SvNV(fromstr))) { + /* 255 is a pretty arbitrary choice, but with + * inf/-inf/nan and 256 bytes there is not much room. */ + aiv = 255; + Perl_ck_warner(aTHX_ packWARN(WARN_PACK), + "Character in 'c' format overflow in pack"); + } + else + aiv = SvIV(fromstr); if ((-128 > aiv || aiv > 127)) Perl_ck_warner(aTHX_ packWARN(WARN_PACK), "Character in 'c' format wrapped in pack"); @@ -2555,7 +2563,14 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) while (len-- > 0) { IV aiv; fromstr = NEXTFROM; - aiv = SvIV(fromstr); + if (SvNOK(fromstr) && Perl_isinfnan(SvNV(fromstr))) { + /* See the 'c' case. */ + aiv = 255; + Perl_ck_warner(aTHX_ packWARN(WARN_PACK), + "Character in 'C' format overflow in pack"); + } + else + aiv = SvIV(fromstr); if ((0 > aiv || aiv > 0xff)) Perl_ck_warner(aTHX_ packWARN(WARN_PACK), "Character in 'C' format wrapped in pack"); |