From 72dbcb4b16ba8abae7db52f83482564e4d62acc4 Mon Sep 17 00:00:00 2001 From: John Tobey Date: Tue, 24 Jun 1997 23:44:33 +1200 Subject: Re: Can't pack literals as pointers MHO, pack("p","foo") should evaluate to a pointer that's valid in the urrent context. pack("p",undef) should return the NULL value. urrently, they both produce the error "Modification of a read-only alue attempted". This looks pretty easy to fix, so I've prepared a diff against the 5.004_01 distribution. This tests fine on my Linux. I hope I'm not introducing a memory leak or other ailment... Credited: Tim Bunce Credited: Gurusamy Sarathy --- pp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pp.c') diff --git a/pp.c b/pp.c index 1cea53fd10..fa36c500dc 100644 --- a/pp.c +++ b/pp.c @@ -3834,7 +3834,14 @@ PP(pp_pack) case 'p': while (len-- > 0) { fromstr = NEXTFROM; - aptr = SvPV_force(fromstr, na); /* XXX Error if TEMP? */ + if (fromstr == &sv_undef) + aptr = NULL; + else { + if (SvREADONLY(fromstr) && curcop != &compiling) { + fromstr = sv_mortalcopy(fromstr); + } + aptr = SvPV_force(fromstr, na); + } sv_catpvn(cat, (char*)&aptr, sizeof(char*)); } break; -- cgit v1.2.1 From d9fdd1afe4b88705294e21dc4e070c42d3d9a4d8 Mon Sep 17 00:00:00 2001 From: "M.J.T. Guy" Date: Tue, 8 Jul 1997 00:37:51 +1200 Subject: Fwd: substr("foo", -1000) Subject: hmmm. Isn't it weird that substr("foo", -1000) is silently converted to substr("foo", 0, 3) while substr("foo", 1000) always causes RETPUSHUNDEF and possibly a warning? I'd say there's too much code in pp.c:pp_substr. Credited: Jarkko Hietaniemi Credited: Tim Bunce p5p-msgid: 9707072304.AA01069@toad.ig.co.uk private-msgid: 199707100655.JAA14924@alpha.hut.fi --- pp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'pp.c') diff --git a/pp.c b/pp.c index fa36c500dc..d791c4b456 100644 --- a/pp.c +++ b/pp.c @@ -1628,11 +1628,8 @@ PP(pp_substr) pos = POPi - arybase; sv = POPs; tmps = SvPV(sv, curlen); - if (pos < 0) { + if (pos < 0) pos += curlen + arybase; - if (pos < 0 && MAXARG < 3) - pos = 0; - } if (pos < 0 || pos > curlen) { if (dowarn || lvalue) warn("substr outside of string"); -- cgit v1.2.1 From ef2d312d3309ac1c38d04eea6f4d58872505013a Mon Sep 17 00:00:00 2001 From: Tom Horsley Date: Wed, 30 Jul 1997 13:24:15 +1200 Subject: work around compiler bug on CX/UX (perl5.004_01) This patch provides a work-around for a compiler bug on CX/UX systems (which shows up as a failure in the 'w' format of pack). The CXUX_BROKEN_CONSTANT_CONVERT ifdef flag is added to the hints/cxux.sh compiler and pp.c is modified to avoid a compile time constant conversion which fails based on that ifdef. While I was in the hints file, I also added the magical -Qtarget=M88110compat compiler option which makes it build code that will run on both 88110 and 88100 CX/UX machines interchangably. This patch was generated from a brand new copy of perl5.004_01, so I'm confident there are no extraneous changes that slipped in. I even built and tested and it passed all tests. (I decided to go with option #3 in my previous mail about how to do the patch). If its too late for 5.004_02, I wouldn't worry - it isn't very critical. p5p-msgid: 9707301934.AA18594@amber.ssd.hcsc.com --- pp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pp.c') diff --git a/pp.c b/pp.c index d791c4b456..a0b337a6e8 100644 --- a/pp.c +++ b/pp.c @@ -15,6 +15,17 @@ #include "EXTERN.h" #include "perl.h" +/* + * The compiler on Concurrent CX/UX systems has a subtle bug which only + * seems to show up when compiling pp.c - it generates the wrong double + * precision constant value for (double)UV_MAX when used inline in the body + * of the code below, so this makes a static variable up front (which the + * compiler seems to get correct) and uses it in place of UV_MAX below. + */ +#ifdef CXUX_BROKEN_CONSTANT_CONVERT +static double UV_MAX_cxux = ((double)UV_MAX); +#endif + /* * Types used in bitwise operations. * @@ -3713,8 +3724,12 @@ PP(pp_pack) if ( #ifdef BW_BITS adouble <= BW_MASK +#else +#ifdef CXUX_BROKEN_CONSTANT_CONVERT + adouble <= UV_MAX_cxux #else adouble <= UV_MAX +#endif #endif ) { -- cgit v1.2.1 From 8490252049bf42d3d2f75d89178a8682bf22ba74 Mon Sep 17 00:00:00 2001 From: Tim Bunce Date: Thu, 7 Aug 1997 00:00:00 +0000 Subject: [inseperable differences up to perl 5.004_02] [editor's note - this list of differences was built manually, so is either a little inaccurate or the most well preened out of the "unapplied changes" lists so far. It certainly didn't get the usual injection of message bodies. The aim of these changes is to give you a vector for finding a list message if you have an annotate operation hit this commit] ------ BUILD PROCESS ------ Title: "[PATCH]: HP-UX 10 w/o transition links" From: Jeff Okamoto Msg-ID: <199706231650.AA070364627@hpcc123.corp.hp.com> Files: Configure Title: "INSTALL updates for GNU ld and __inet_* errors" From: Andy Dougherty Files: INSTALL ------ CORE LANGUAGE ------ Title: "[PATCH] Additional patch for "Can't execute ..."" From: Ilya Zakharevich Msg-ID: <199707191651.MAA04897@monk.mps.ohio-state.edu> Files: pod/perldiag.pod perl.c See 21fc060b433a5fd003b9aca5789342207c46ada4 and 2a92aaa05aa1acbf01092228d30e9b1d7b2a3f61 Title: "[PATCH] Re: Can't pack literals as pointers" From: Gurusamy Sarathy Msg-ID: <199708012250.SAA20278@aatma.engin.umich.edu> Files: pod/perldiag.pod pod/perlfunc.pod pp.c t/op/pack.t On Wed, 25 Jun 1997 00:23:18 GMT, John Tobey wrote: > >IMHO, pack("p","foo") should evaluate to a pointer that's valid >in the current context. pack("p",undef) should return the NULL >value. Currently, they both produce the error "Modification of a >read-only value attempted". > >This looks pretty easy to fix, so I've prepared a diff against >the 5.004_01 distribution. This tests fine on my Linux. I hope >I'm not introducing a memory leak or other ailment... That doesn't look quite right to me. When provided a literal, you should point at the actual literal (which normally has a global lifetime), rather than making a mortal copy of it and pointing at that. The mortal copy will be destroyed at the next statement boundary, and you'll be left with a dangling pointer when you unpack(). You're doing the very thing the XXX comment above was intended to highlight. I do agree that literals should be pack('p')-able. So, I'd suggest the change be modified [...] Title: "One-liner regex causes SEGV on 5.003 under HP-UX and Linux" From: Hugo van der Sanden Msg-ID: <199707061144.MAA04443@crypt.compulink.co.uk> Files: regexec.c t/op/re_tests [was originally credited as the same change as 44ed422101809141bc33c2b85c1cff357de4d7bf] Title: "Free temps before calling END blocks", "Too late destruction" From: Chip Salzenberg Msg-ID: Files: perl.c Title: "Forbid "goto" into middle of foreach loop" From: Chip Salzenberg Files: pod/perldiag.pod pp_ctl.c Title: "[PATCH] m2t2: problem in NetBSD 1.2D with sfio" From: Jarkko Hietaniemi Files: perl.h Title: "Forbid negative splice offset beyond array start" From: "John L. Allen" , Chip Salzenberg Msg-ID: Files: pp.c Title: "Fix memory leak on eval 'sub {}'" From: Chip Salzenberg Files: pp_ctl.c Title: "Fix C" From: Chip Salzenberg Files: toke.c Title: "Don't warn about "${foo}" in string, even if &foo exists" From: Chip Salzenberg Files: toke.c Title: "Perldb internal flag rehaul" From: Ilya Zakharevich Files: pod/perldebug.pod pod/perlvar.pod perl.h gv.c mg.c op.c perl.c pp_ctl.c pp_hot.c pp_sys.c sv.c toke.c Title: "Fix C parsing" From: "Chuck D. Phillips (NON-HP Employee)" , Chip Salzenberg Msg-ID: <199706121737.KAA00503@palrel3.hp.com> Files: toke.c Title: "Fix lockf_emulate_flock() positioning" From: Chip Salzenberg , gen@atd.rdc.ricoh.co.jp Msg-ID: <199706091132.UAA00895@wampa.atd.rdc.ricoh.co.jp> Files: pp_sys.c Title: "[PATCH] Make DEBUGGING_MSTATS info consistent" From: Andy Dougherty Msg-ID: Files: INSTALL pod/perldelta.pod perl.h Title: "semctl broken under Linux" From: Andreas Schwab , Andreas Schwab , Graham Barr , Tim Bunce Msg-ID: <33C38291.2D9302DA@ti.com>, <9707040912.AA03470@issan.informatik.uni-dortmund.de>, <9707041538.AA08946@toad.ig.co.uk>, <9707070924.AA11774@issan.informatik.uni-dortmund.de>, <9707090933.AA19012@issan.informatik.uni-dortmund.de> Files: doio.c [one change made it, as 8e591e46b4c6543ed80895327199c4a628ce11b6] Title: "One-liner regex causes SEGV on 5.003 under HP-UX and Linux" From: Hugo van der Sanden Msg-ID: <199707061144.MAA04443@crypt.compulink.co.uk> Files: regexec.c t/op/re_tests [was originally credited as the same change as 44ed422101809141bc33c2b85c1cff357de4d7bf] Title: "Fix up problems with *DBM tests" From: Paul Marquess Files: t/lib/gdbm.t t/lib/ndbm.t t/lib/odbm.t t/lib/sdbm.t Title: "Faster int to string conversion", "[PATCH} Re: memory leak in buffer safety code" From: Chip Salzenberg , Hugo van der Sanden , Tim Bunce Msg-ID: <199707140912.KAA09935@crypt.compulink.co.uk>, <199707142050.QAA20976@rio.atlantic.net>, <199707182035.VAA20990@crypt.compulink.co.uk>, <9707151040.AA02883@toad.ig.co.uk> Files: global.sym sv.c Title: "Fix '-' flag on sprintf() of floats" From: Chip Salzenberg , Jarkko Hietaniemi Msg-ID: <199705270646.JAA02510@alpha.hut.fi> Files: sv.c Title: "Don't use atol() for unsigned values", "signedness problem in pack("N", "value");" From: Chip Salzenberg , Roger Espel Llima Msg-ID: <19970531200007.40218@llaic.univ-bpclermont.fr> Files: sv.c Title: "Perldb internal flag rehaul" From: Ilya Zakharevich Files: pod/perldebug.pod pod/perlvar.pod perl.h gv.c mg.c op.c perl.c pp_ctl.c pp_hot.c pp_sys.c sv.c toke.c Title: "[PATCH] Exporter new export_to_level method" From: epeschko@elmer.tci.com (Ed Peschko) Files: lib/Exporter.pm Title: "[MM] Small patch to MakeMaker, new release" From: "Andreas J. Koenig" Msg-ID: <199706281603.SAA10869@anna.in-berlin.de> Files: lib/ExtUtils/Command.pm lib/ExtUtils/Install.pm lib/ExtUtils/Liblist.pm lib/ExtUtils/MM_Unix.pm lib/ExtUtils/MakeMaker.pm lib/ExtUtils/Mksymlists.pm Title: "CPAN.pm, $VERSION and nested (bundled) modules." From: a.koenig@kulturbox.de (Andreas J. Koenig) Files: lib/ExtUtils/Install.pm lib/ExtUtils/Liblist.pm lib/ExtUtils/MM_Unix.pm lib/ExtUtils/MakeMaker.pm lib/ExtUtils/Mksymlists.pm Title: "Time::Local patch (plus perl.c and filehand.t)" From: ilya@math.ohio-state.edu (Ilya Zakharevich) Files: lib/Time/Local.pm perl.c t/lib/filehand.t Title: "Slightly safer signals" From: Ilya Zakharevich Files: mg.c perl.c Title: "Perldb internal flag rehaul" From: Ilya Zakharevich Files: pod/perldebug.pod pod/perlvar.pod perl.h gv.c mg.c op.c perl.c pp_ctl.c pp_hot.c pp_sys.c sv.c toke.c Title: "'use UNIVERSAL;' deprecated, do C instead", "UNIVERSAL.pm and import methods" From: "M.J.T. Guy" , Gisle Aas , Graham Barr , Gurusamy Sarathy , Hugo van der Sanden Msg-ID: <199706271701.NAA25664@aatma.engin.umich.edu>, <199706271904.UAA00120@crypt.compulink.co.uk>, <199706272054.QAA28913@aatma.engin.umich.edu>, <199706301554.LAA03763@aatma.engin.umich.edu>, <33B22248.7D7C1985@ti.com>, , , , , , Files: lib/Class/Struct.pm lib/File/Compare.pm lib/File/Copy.pm t/op/universal.t universal.c [two changes made it, as d704f39a0db2dc23790dfd9d7bd59ce9928a6e2c, e09f3e01ccd721309f0eb0aae224d84db2e8436a] ------ PORTABILITY - WIN32 ------ Title: "[PATCH] Embedding threaded apps in perl.dll" From: Gurusamy Sarathy Msg-ID: <199707261518.LAA24346@aatma.engin.umich.edu>, <199707301833.OAA19570@aatma.engin.umich.edu> Files: win32/win32.c [one change made it, as 4dd614da4d1132b957c4951dd00f64d81b89dc20] Title: "minor win32 scribbles" From: Hugo van der Sanden Msg-ID: <199707270832.JAA19399@crypt.compulink.co.uk> Files: README.win32 [nitpicking f7c603cbfba7c97f77e257c42aa119ffdb47fe1e] Title: "[PATCH] binary coexistence on win32", "[RESEND] [PATCH] binary coexistence on win32" From: Gurusamy Sarathy Msg-ID: <199707250109.VAA02666@aatma.engin.umich.edu>, <199707301829.OAA19516@aatma.engin.umich.edu> Files: lib/ExtUtils/Mksymlists.pm win32/win32.h win32/win32io.h win32/win32iop.h win32/makedef.pl win32/win32.c win32/win32io.c Title: "WIN32 Build - pod2xxx.bat Missing?", "[PATCH] Re: WIN32 Build - pod2xxx.bat Missing?" From: Chris Williams , Gurusamy Sarathy Msg-ID: <199707011423.KAA15855@aatma.engin.umich.edu>, <33B8B962.D96FA1F5@netinfo.com.au> Files: win32/Makefile win32/makefile.mk Title: "[PATCH] docs for win32 utilities" From: Gurusamy Sarathy Msg-ID: <199707250045.UAA02510@aatma.engin.umich.edu> Files: win32/bin/pl2bat.bat win32/bin/runperl.bat Title: "[PATCH] trial2: some batch files won't run" From: Gurusamy Sarathy Msg-ID: <199708040226.WAA17301@aatma.engin.umich.edu> Files: win32/bin/pl2bat.bat win32/bin/runperl.bat Title: "[PATCH] win32 extras and embedding" From: Gurusamy Sarathy Msg-ID: <199707250232.WAA03421@aatma.engin.umich.edu>, <199707301831.OAA19528@aatma.engin.umich.edu> Files: dosish.h win32/win32.h perl.c win32/config.bc win32/config_H.bc win32/makedef.pl win32/perllib.c win32/win32.c [one change was applied (hastily), as ad2e33dc060dc2ccf73a5ff1557a69a9b09c30c8] ------ PORTABILITY - OTHER ------ Title: "Additional OS/2 patches" From: Gurusamy Sarathy , Ilya Zakharevich Msg-ID: <199708020823.EAA19521@monk.mps.ohio-state.edu>, <199708021424.KAA28561@aatma.engin.umich.edu>, <199708042108.RAA27671@aatma.engin.umich.edu> Files: README.os2 os2/Changes perl.c [one change was applied, as d8c2d278168b862ff4120ad8e5887d37d31f858b] Title: "make depend loop fix and minor OS/2 improvements to build process" From: ilya@math.ohio-state.edu (Ilya Zakharevich) Files: Makefile.SH hints/os2.sh os2/Makefile.SHs Title: "Minor VMS patches" From: Charles Bailey Msg-ID: <01ILCUO6XXTE000WFK@hmivax.humgen.upenn.edu> Files: lib/ExtUtils/MM_VMS.pm vms/vmsish.h vms/descrip.mms vms/test.com vms/vms.c vms/ext/filespec.t Title: "[PATCH] Two un-disabled tests for VMS" From: Dan Sugalski Msg-ID: <3.0.2.32.19970718095842.00879220@stargate.lbcc.cc.or.us> Files: vms/test.com Title: "fix substr fix (tests 27 etc)", "perl5.004_02 trial 1 available (with substr bug and still some" From: "M.J.T. Guy" , Hugo van der Sanden , Jarkko Hietaniemi Msg-ID: <199707301759.SAA02899@crypt.compulink.co.uk>, <199707302228.BAA18032@alpha.hut.fi>, <199707310929.KAA06515@crypt.compulink.co.uk>, Files: pp.c Title: "Fwd: substr("foo", -1000)", "substr: warn if substring doesn't intersect original at all" From: "M.J.T. Guy" , Jarkko Hietaniemi Msg-ID: <199707100655.JAA14924@alpha.hut.fi>, Files: pod/perlfunc.pod pp.c t/op/substr.t [one change was applied, as d9fdd1afe4b88705294e21dc4e070c42d3d9a4d8] Title: "[PATCH] Changes for VMS 7.1 support" From: Charles Bailey , Dan Sugalski Msg-ID: <01ILDXUH0J1W00026U@hmivax.humgen.upenn.edu>, <3.0.2.32.19970718095935.0087a2d0@stargate.lbcc.cc.or.us> Files: vms/sockadapt.h vms/config.vms vms/sockadapt.c ------ DOCUMENTATION ------ Title: "Document bug fix in localization of $1 etc." From: Chip Salzenberg Files: pod/perldelta.pod Title: "[BUG:PATCH] Missing semicolon message wrong in perldiag" From: "M.J.T. Guy" Msg-ID: , Files: pod/perldiag.pod [one change was applied, as 702d120df290e0de1b21f167f7d0110b35ee2fef] Title: "OK: perl on (corrected)", "enhancements to perlbug -ok" From: "M.J.T. Guy" , Stephen McCamant Msg-ID: , , Files: utils/Makefile utils/perlbug.PL Title: "perldoc doesn't grok Win32 UNC paths" From: Warren Jones Msg-ID: <97Jun17.184420pdt.35728-1@gateway.fluke.com>, <97Jun18.165618pdt.35713-1@gateway.fluke.com> Files: utils/perldoc.PL [one change was applied, as f72119fc50f0d88b02501ba41112f82ab99f0c3b] --- pp.c | 79 +++++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 27 deletions(-) (limited to 'pp.c') diff --git a/pp.c b/pp.c index a0b337a6e8..8a31fff881 100644 --- a/pp.c +++ b/pp.c @@ -1630,34 +1630,56 @@ PP(pp_substr) STRLEN curlen; I32 pos; I32 rem; + I32 fail; I32 lvalue = op->op_flags & OPf_MOD; char *tmps; I32 arybase = curcop->cop_arybase; if (MAXARG > 2) len = POPi; - pos = POPi - arybase; + pos = POPi; sv = POPs; tmps = SvPV(sv, curlen); - if (pos < 0) - pos += curlen + arybase; - if (pos < 0 || pos > curlen) { - if (dowarn || lvalue) + if (pos >= arybase) { + pos -= arybase; + rem = curlen-pos; + fail = rem; + if (MAXARG > 2) { + if (len < 0) { + rem += len; + if (rem < 0) + rem = 0; + } + else if (rem > len) + rem = len; + } + } + else { + pos += curlen; + if (MAXARG < 3) + rem = curlen; + else if (len >= 0) { + rem = pos+len; + if (rem > (I32)curlen) + rem = curlen; + } + else { + rem = curlen+len; + if (rem < pos) + rem = pos; + } + if (pos < 0) + pos = 0; + fail = rem; + rem -= pos; + } + if (fail < 0) { + if (dowarn || lvalue) warn("substr outside of string"); RETPUSHUNDEF; } else { - if (MAXARG < 3) - len = curlen; - else if (len < 0) { - len += curlen - pos; - if (len < 0) - len = 0; - } tmps += pos; - rem = curlen - pos; /* rem=how many bytes left*/ - if (rem > len) - rem = len; sv_setpvn(TARG, tmps, rem); if (lvalue) { /* it's an lvalue! */ if (!SvGMAGICAL(sv)) { @@ -2328,11 +2350,13 @@ PP(pp_splice) SP++; if (++MARK < SP) { - offset = SvIVx(*MARK); + offset = i = SvIVx(*MARK); if (offset < 0) offset += AvFILL(ary) + 1; else offset -= curcop->cop_arybase; + if (offset < 0) + DIE(no_aelem, i); if (++MARK < SP) { length = SvIVx(*MARK++); if (length < 0) @@ -2345,12 +2369,6 @@ PP(pp_splice) offset = 0; length = AvMAX(ary) + 1; } - if (offset < 0) { - length += offset; - offset = 0; - if (length < 0) - length = 0; - } if (offset > AvFILL(ary) + 1) offset = AvFILL(ary) + 1; after = AvFILL(ary) + 1 - (offset + length); @@ -3847,12 +3865,19 @@ PP(pp_pack) while (len-- > 0) { fromstr = NEXTFROM; if (fromstr == &sv_undef) - aptr = NULL; + aptr = NULL; else { - if (SvREADONLY(fromstr) && curcop != &compiling) { - fromstr = sv_mortalcopy(fromstr); - } - aptr = SvPV_force(fromstr, na); + /* XXX better yet, could spirit away the string to + * a safe spot and hang on to it until the result + * of pack() (and all copies of the result) are + * gone. + */ + if (dowarn && (SvTEMP(fromstr) || SvPADTMP(fromstr))) + warn("Attempt to pack pointer to temporary value"); + if (SvPOK(fromstr) || SvNIOK(fromstr)) + aptr = SvPV(fromstr,na); + else + aptr = SvPV_force(fromstr,na); } sv_catpvn(cat, (char*)&aptr, sizeof(char*)); } -- cgit v1.2.1