home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5867 < prev    next >
Encoding:
Text File  |  1992-09-11  |  3.9 KB  |  123 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!nigel.msen.com!caen!sdd.hp.com!ux1.cso.uiuc.edu!milo.mcs.anl.gov!olson
  3. From: olson@mcs.anl.gov (Bob Olson)
  4. Subject: Perl bug? Crash in reference to $' after re match
  5. Message-ID: <OLSON.92Sep11105510@locke.mcs.anl.gov>
  6. Lines: 112
  7. Sender: usenet@mcs.anl.gov
  8. Organization: Math & Computer Science Divison, ANL
  9. Date: Fri, 11 Sep 1992 16:55:09 GMT
  10.  
  11. Another strange perl crash for y'all. This is on a NeXT running OS
  12. 3.0PR2.  The crash also shows up on NeXT OS2.1, an IBM RS/6K running
  13. AIX 3.2, and on the SGI running IRIX 4.0.4. On a sun4 running 4.1.1,
  14. we get no crash but the while loop aborts strangely. (i.e. if I insert
  15. the statement
  16.  
  17.         print "Got '$a'\n";
  18.  
  19. after the assignment to $a, a run looks like:
  20.  
  21.     (dalek) % perl ~/PCN/CF/v0.4/CF/explode
  22.     Got'
  23. )
  24.  
  25. The code:
  26. --------------------------------------------------
  27. #!/usr/local/bin/perl
  28.  
  29. $_ = "    abcdeggh;\n";
  30.  
  31.  
  32. $var = "abcdeg";
  33. while (/\b($var)/g)
  34. {
  35.     $a = $';
  36. }
  37. --------------------------------------------------
  38.  
  39. If the string that matches (abcdeg above) is shortened, there is no
  40. crash. If the reference to $' is removed, there is no crash. If the \b
  41. or parens or /g in the regexp match are removed, there is no crash.
  42.  
  43. The run:
  44. --------------------------------------------------
  45. (locke) % perl explode
  46. Out of memory!
  47. --------------------------------------------------
  48. (locke) % perl -v 
  49.  
  50. This is perl, version 4.0
  51.  
  52. $RCSfile: perl.c,v $$Revision: 4.0.1.7 $$Date: 92/06/08 14:50:39 $
  53. Patch level: 35
  54.  
  55. Copyright (c) 1989, 1990, 1991, Larry Wall
  56.  
  57. Perl may be copied only under the terms of either the Artistic License or the
  58. GNU General Public License, which may be found in the Perl 4.0 source kit.
  59. --------------------------------------------------
  60.  
  61. And the gdb session. We crash because we are passing -2 down to the
  62. str_grow routine, who interprets it as an unsigned integer of value
  63. 4294967295. 
  64.  
  65. --------------------------------------------------
  66. Current directory is /mcs/source/Perl/perl-4.035/next-3.0/
  67. Reading symbol data from perl...done.
  68. Reading symbol data from /usr/shlib/libsys_s.B.shlib...done.
  69. (gdb) b exit
  70. Breakpoint 1 at 0x5052fd8
  71. (gdb) r explode
  72. Starting program: /mcs/source/Perl/perl-4.035/next-3.0/perl explode
  73. Out of memory!
  74.  
  75. Breakpoint 1, 0x5052fd8 in exit ()
  76. (gdb) where
  77. #0  0x5052fd8 in exit ()
  78. #1  0x3798e in safemalloc (size=4294967295) at util.c:123
  79. #2  0x2c520 in str_grow (str=0xd7c80, newlen=-1) at str.c:129
  80. #3  0x2c958 in str_nset (str=0xd7c80, ptr=0xd5efe "gh;\n", len=4294967294) at str.c:330
  81. #4  0x29e10 in stab_str (str=0xd7bfc) at stab.c:140
  82. #5  0x1a17e in eval (arg=0xd7d00, gimme=0, sp=1) at eval.c:241
  83. #6  0x540e in cmd_exec (cmdparm=0xd7d44, gimme=0, sp=-1) at cmd.c:654
  84. #7  0x5ae6 in cmd_exec (cmdparm=0xd57e8, gimme=0, sp=-1) at cmd.c:890
  85. #8  0x25720 in main (argc=0, argv=0x3fffed0, env=0x3fffed4) at perl.c:890
  86. (gdb) frame 2
  87. #2  0x2c520 in str_grow (str=0xd7c80, newlen=-1) at str.c:129
  88. (gdb) list
  89. 124        }
  90. 125        if (newlen > str->str_len) {        /* need more room? */
  91. 126            if (str->str_len)
  92. 127            Renew(s,newlen,char);
  93. 128            else
  94. 129            New(703,s,newlen,char);
  95. 130        str->str_ptr = s;
  96. 131            str->str_len = newlen;
  97. 132        }
  98. 133        return s;
  99. (gdb) up
  100. #3  0x2c958 in str_nset (str=0xd7c80, ptr=0xd5efe "gh;\n", len=4294967294) at str.c:330
  101. (gdb) up
  102. #4  0x29e10 in stab_str (str=0xd7bfc) at stab.c:140
  103. (gdb) list
  104. 135        break;
  105. 136        case '\'':
  106. 137        if (curspat) {
  107. 138            if (curspat->spat_regexp &&
  108. 139              (s = curspat->spat_regexp->endp[0]) ) {
  109. 140            str_nset(stab_val(stab),s, curspat->spat_regexp->subend - s);
  110. 141            }
  111. 142            else
  112. 143            str_nset(stab_val(stab),"",0);
  113. 144        }
  114. (gdb) p curspat->spat_regexp->subend - s
  115. $1 = 0xd5efc "eggh;\n"
  116. (gdb) p s
  117. $2 = 0xd5efe "gh;\n"
  118. (gdb) p curspat->spat_regexp->subend - s
  119. $3 = -2
  120. --
  121.    Bob Olson   -*-   olson@mcs.anl.gov   -*-   Argonne National Laboratory
  122.      "You can't win a game of chess with an action figure!" --bob&dave
  123.