X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp.c;h=8877d8a469434c5f4992a6f00902a7e25dfd06bc;hb=23f3aea032e3289acf8e6a178372c27e8e03f4a0;hp=1649cf4d2cb2f314159575e83cec7a0efd9f6db6;hpb=ce58e4c2a04da0fdbc16746698a37cdef4d70f56;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp.c b/pp.c index 1649cf4..8877d8a 100644 --- a/pp.c +++ b/pp.c @@ -561,7 +561,11 @@ PP(pp_bless) else { SV *ssv = POPs; STRLEN len; - char *ptr = SvPV(ssv,len); + char *ptr; + + if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv)) + Perl_croak(aTHX_ "Attempt to bless into a reference"); + ptr = SvPV(ssv,len); if (ckWARN(WARN_MISC) && len == 0) Perl_warner(aTHX_ WARN_MISC, "Explicit blessing to '' (assuming package main)"); @@ -599,6 +603,9 @@ PP(pp_gelem) case 'F': if (strEQ(elem, "FILEHANDLE")) /* XXX deprecate in 5.005 */ tmpRef = (SV*)GvIOp(gv); + else + if (strEQ(elem, "FORMAT")) + tmpRef = (SV*)GvFORM(gv); break; case 'G': if (strEQ(elem, "GLOB")) @@ -1813,7 +1820,7 @@ PP(pp_log) NV value; value = POPn; if (value <= 0.0) { - RESTORE_NUMERIC_STANDARD(); + SET_NUMERIC_STANDARD(); DIE(aTHX_ "Can't take log of %g", value); } value = Perl_log(value); @@ -1829,7 +1836,7 @@ PP(pp_sqrt) NV value; value = POPn; if (value < 0.0) { - RESTORE_NUMERIC_STANDARD(); + SET_NUMERIC_STANDARD(); DIE(aTHX_ "Can't take sqrt of %g", value); } value = Perl_sqrt(value); @@ -2188,7 +2195,7 @@ PP(pp_ord) I32 retlen; if ((*tmps & 0x80) && DO_UTF8(tmpsv)) - value = utf8_to_uv(tmps, &retlen); + value = utf8_to_uv_chk(tmps, &retlen, 0); else value = (UV)(*tmps & 255); XPUSHu(value); @@ -2203,7 +2210,7 @@ PP(pp_chr) (void)SvUPGRADE(TARG,SVt_PV); - if (value > 255 && !IN_BYTE) { + if ((value > 255 && !IN_BYTE) || (value & 0x80 && PL_hints & HINT_UTF8) ) { SvGROW(TARG, UTF8_MAXLEN+1); tmps = SvPVX(TARG); tmps = (char*)uv_to_utf8((U8*)tmps, (UV)value); @@ -2255,7 +2262,7 @@ PP(pp_ucfirst) I32 ulen; U8 tmpbuf[UTF8_MAXLEN]; U8 *tend; - UV uv = utf8_to_uv(s, &ulen); + UV uv = utf8_to_uv_chk(s, &ulen, 0); if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2314,7 +2321,7 @@ PP(pp_lcfirst) I32 ulen; U8 tmpbuf[UTF8_MAXLEN]; U8 *tend; - UV uv = utf8_to_uv(s, &ulen); + UV uv = utf8_to_uv_chk(s, &ulen, 0); if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2391,7 +2398,7 @@ PP(pp_uc) TAINT; SvTAINTED_on(TARG); while (s < send) { - d = uv_to_utf8(d, toUPPER_LC_uni( utf8_to_uv(s, &ulen))); + d = uv_to_utf8(d, toUPPER_LC_uni( utf8_to_uv_chk(s, &ulen, 0))); s += ulen; } } @@ -2465,7 +2472,7 @@ PP(pp_lc) TAINT; SvTAINTED_on(TARG); while (s < send) { - d = uv_to_utf8(d, toLOWER_LC_uni( utf8_to_uv(s, &ulen))); + d = uv_to_utf8(d, toLOWER_LC_uni( utf8_to_uv_chk(s, &ulen, 0))); s += ulen; } } @@ -3607,7 +3614,7 @@ PP(pp_unpack) len = strend - s; if (checksum) { while (len-- > 0 && s < strend) { - auint = utf8_to_uv((U8*)s, &along); + auint = utf8_to_uv_chk((U8*)s, &along, 0); s += along; if (checksum > 32) cdouble += (NV)auint; @@ -3619,7 +3626,7 @@ PP(pp_unpack) EXTEND(SP, len); EXTEND_MORTAL(len); while (len-- > 0 && s < strend) { - auint = utf8_to_uv((U8*)s, &along); + auint = utf8_to_uv_chk((U8*)s, &along, 0); s += along; sv = NEWSV(37, 0); sv_setuv(sv, (UV)auint); @@ -4038,7 +4045,7 @@ PP(pp_unpack) char *t; STRLEN n_a; - sv = Perl_newSVpvf(aTHX_ "%.*Vu", (int)TYPE_DIGITS(UV), auv); + sv = Perl_newSVpvf(aTHX_ "%.*"UVf, (int)TYPE_DIGITS(UV), auv); while (s < strend) { sv = mul128(sv, *s & 0x7f); if (!(*s++ & 0x80)) { @@ -4418,7 +4425,7 @@ PP(pp_pack) patcopy++; continue; } - if (datumtype == 'U' && pat==patcopy+1) + if (datumtype == 'U' && pat == patcopy+1) SvUTF8_on(cat); if (datumtype == '#') { while (pat < patend && *pat != '\n') @@ -4967,6 +4974,7 @@ PP(pp_split) AV *ary; register I32 limit = POPi; /* note, negative is forever */ SV *sv = POPs; + bool isutf = DO_UTF8(sv); STRLEN len; register char *s = SvPV(sv, len); char *strend = s + len; @@ -5069,6 +5077,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + 1; @@ -5089,6 +5099,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m; } @@ -5112,6 +5124,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + 1; } @@ -5127,6 +5141,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + len; /* Fake \n at the end */ } @@ -5154,6 +5170,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); if (rx->nparens) { for (i = 1; i <= rx->nparens; i++) { @@ -5167,6 +5185,8 @@ PP(pp_split) dstr = NEWSV(33, 0); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); } } @@ -5185,6 +5205,8 @@ PP(pp_split) sv_setpvn(dstr, s, strend-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); iters++; }