Closed p5pRT closed 12 years ago
It would appear that 'use bigint;' doesn't interact with self generating regexes using the '(??{})' construct. This shows up when the RE construct is used to select a number of characters based upon a preceding capture buffer. Eg the code below should pull out 'abc':
"03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n"
Run the same code with 'use bigint;':
use bigint; "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n"
and the RE doesn't match and $' is filled with garbage\, which would appear to be the memory of the process.
If the output of the sprintf() is captured it contains the correct value in both cases\, ie '.{3}'. This has been checked under 5.10.1 and 5.12.1.
On Tue Sep 13 08:17:35 2011\, jerry@nightwatch.org.uk wrote:
"03abcde" =~ /^\(\.\.\)\(\(??\{sprintf"\.\{%d\}"\,hex\("0x$1"\)\}\)\)/; print "$\`​:$&​:$' \-> \[$1\] \[$2\]\\n"
Run the same code with 'use bigint;':
use bigint; "03abcde" =~ /^\(\.\.\)\(\(??\{sprintf"\.\{%d\}"\,hex\("0x$1"\)\}\)\)/; print "$\`​:$&​:$' \-> \[$1\] \[$2\]\\n"
and the RE doesn't match and $' is filled with garbage\, which would appear to be the memory of the process.
I get a somewhat different result.
### "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n";
use bigint; "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n"; ###
... produces:
### :03abc:de -> [03] [abc] Use of uninitialized value $2 in concatenation (.) or string at 99026.pl line 13. :03abc:de -> [03] [] ###
... i.e.\, no garbage\, but no good results either. (Perl 5.14.2/Linux i386)
Thank you very much. Jim Keenan
The RT System itself - Status changed from 'new' to 'open'
Running the test code under valgrind gives:
:03abc:de -> [03] [abc] ==7658== Invalid read of size 4 ==7658== at 0x82C10FC: S_regcppush (regexec.c:369) ==7658== by 0x82DA88F: S_regmatch (regexec.c:4391) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== by 0x8093E39: perl_run (perl.c:2301) ==7658== by 0x80603EC: main (perlmain.c:120) ==7658== Address 0x4277974 is 20 bytes inside a block of size 28 free'd ==7658== at 0x4024046: realloc (vg_replace_malloc.c:525) ==7658== by 0x815B25D: Perl_safesysrealloc (util.c:193) ==7658== by 0x82D162A: S_regtry (regexec.c:2653) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B839C: Perl_pp_subst (pp_hot.c:2151) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x82D9D3F: S_regmatch (regexec.c:4275) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== ==7658== Invalid write of size 4 ==7658== at 0x82C15F5: S_regcppop (regexec.c:430) ==7658== by 0x82DF03A: S_regmatch (regexec.c:5492) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== by 0x8093E39: perl_run (perl.c:2301) ==7658== by 0x80603EC: main (perlmain.c:120) ==7658== Address 0x4277970 is 16 bytes inside a block of size 28 free'd ==7658== at 0x4024046: realloc (vg_replace_malloc.c:525) ==7658== by 0x815B25D: Perl_safesysrealloc (util.c:193) ==7658== by 0x82D162A: S_regtry (regexec.c:2653) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B839C: Perl_pp_subst (pp_hot.c:2151) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x82D9D3F: S_regmatch (regexec.c:4275) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== ==7658== Invalid read of size 4 ==7658== at 0x82DB29E: S_regmatch (regexec.c:4490) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== by 0x8093E39: perl_run (perl.c:2301) ==7658== by 0x80603EC: main (perlmain.c:120) ==7658== Address 0x4277974 is 20 bytes inside a block of size 28 free'd ==7658== at 0x4024046: realloc (vg_replace_malloc.c:525) ==7658== by 0x815B25D: Perl_safesysrealloc (util.c:193) ==7658== by 0x82D162A: S_regtry (regexec.c:2653) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B839C: Perl_pp_subst (pp_hot.c:2151) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x82D9D3F: S_regmatch (regexec.c:4275) ==7658== by 0x82D174D: S_regtry (regexec.c:2683) ==7658== by 0x82CE7E4: Perl_regexec_flags (regexec.c:2173) ==7658== by 0x81B1EF7: Perl_pp_match (pp_hot.c:1355) ==7658== by 0x815A603: Perl_runops_debug (dump.c:2118) ==7658== by 0x8094BDE: S_run_body (perl.c:2383) ==7658== :03abc:de -> [03] []
Nicholas Clark
I get a somewhat different result.
### "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n";
use bigint; "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n"; ###
... produces:
### :03abc:de -> [03] [abc] Use of uninitialized value $2 in concatenation (.) or string at 99026.pl line 13. :03abc:de -> [03] [] ###
... i.e.\, no garbage\, but no good results either. (Perl 5.14.2/Linux i386)
Ah\, sorry that wasn't very clear regarding the code snippets. If you run them as separate pieces of code\, i.e.:
"03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n";
and then with the "use bigint;"
use bigint; "03abcde" =~ /^(..)((??{sprintf".{%d}"\,hex("0x$1")}))/; print "$`:$&:$' -> [$1] [$2]\n";
That way you'll see the difference. I've just tested\, and if run separately I get the garbage for the second chunk\, but together I get valid output just like you had (apart from the second RE didn't match when it should have).
Jerry.
On Tue Dec 06 15:03:02 2011\, jerry@nightwatch.org.uk wrote:
Ah\, sorry that wasn't very clear regarding the code snippets. If you run them as separate pieces of code\, i.e.:
"03abcde" =~ /^\(\.\.\)\(\(??\{sprintf"\.\{%d\}"\,hex\("0x$1"\)\}\)\)/; print "$\`​:$&​:$' \-> \[$1\] \[$2\]\\n";
and then with the "use bigint;"
use bigint; "03abcde" =~ /^\(\.\.\)\(\(??\{sprintf"\.\{%d\}"\,hex\("0x$1"\)\}\)\)/; print "$\`​:$&​:$' \-> \[$1\] \[$2\]\\n";
That way you'll see the difference. I've just tested\, and if run separately I get the garbage for the second chunk\, but together I get valid output just like you had (apart from the second RE didn't match when it should have).
But I find that even if I separate the chunks into separate files\, I get the same results I previously posted (which\, to make a correction\, were from Darwin; what follows is from Linux):
##### $ diff 99026.pl bigint_99026.pl 7a8
use bigint;
$ perl 99026.pl ;perl bigint_99026.pl :03abc:de -> [03] [abc]
Use of uninitialized value $2 in concatenation (.) or string at bigint_99026.pl line 10. :03abc:de -> [03] []
#####
This has been fixed by the commits leading up to eb58a7e122.
@cpansprout - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#99026 (status was 'resolved')
Searchable as RT99026$