home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5338 < prev    next >
Encoding:
Internet Message Format  |  1992-08-16  |  4.9 KB

  1. Path: sparky!uunet!wupost!usc!rpi!usenet.coe.montana.edu!news.u.washington.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!mach.cs.cmu.edu!jfriedl
  2. From: jfriedl+@cs.cmu.edu (Jeffrey E. F. Friedl)
  3. Newsgroups: comp.lang.perl
  4. Subject: array bug (not infinite recursion)
  5. Message-ID: <Bt3F0D.G3K.1@cs.cmu.edu>
  6. Date: 16 Aug 92 20:17:00 GMT
  7. Article-I.D.: cs.Bt3F0D.G3K.1
  8. References: <Bt1rC8.E6J.1@cs.cmu.edu>
  9. Sender: news@cs.cmu.edu (Usenet News System)
  10. Reply-To: jfriedl@cs.cmu.edu
  11. Organization: Carnegie Mellon / Omron Corporation
  12. Lines: 119
  13. Nntp-Posting-Host: tubby.mach.cs.cmu.edu
  14.  
  15. I wrote:
  16.  
  17. |> The following (contrived) program dumps core with 4.035
  18. |> 
  19. |>     &foo;
  20. |>     sub foo {
  21. |>         ($a, $b) = &foo('fi','b');
  22. |>     }
  23. |> 
  24. |> I've run it (and had the problem) on Sun 3, Sun 4, IBM-RT,
  25. |> Pmax, Vax, and Luna/88k.
  26.  
  27. Ok,ok, I guess I should have been more verbose and not assumed I would
  28. be taken for a two-year-old (no, even a two-year old knows infinite
  29. recursion is a no-no :-)  I made the mistake of assuming the perl.gods would
  30. actually try the program.  The number of patronizing messages in my mail
  31. box that said "Jeffy, maybe infinite recursion isn't such a hot idea"
  32. indicates that my assumption was a poor one.
  33.  
  34. Perl dumps core before &foo is called a 2nd time (i.e. before it is
  35. called even once recursively).
  36.  
  37. It seems to die when it's trying to save local variables. There are none,
  38. so some pointer is zero. This pointer isn't being checked before being
  39. dereferenced [see code snippet at end of message].  I don't have enough
  40. of a global understanding of the internals to know exactly what's wrong
  41. (i.e. that the pointer isn't being checked, or that it shouldn't be null
  42. to begin with).
  43.  
  44. See the script below for a -D14 run with gdb trace.
  45.  
  46. The following is a more politically correct example:
  47.  
  48.     &foo;
  49.     sub foo {
  50.         ($a, $b) = &foo('','') if $depth++ == 0;
  51.     }
  52.  
  53. *jeff*
  54.  
  55. --------------------------------------------------------------
  56.  
  57. Script started on Sun Aug 16 15:40:19 1992
  58. SHELL> cat foo
  59. &foo;
  60. sub foo {
  61.     ($a, $b) = &foo('','');
  62. }
  63. SHELL> gdb ./perl
  64. GDB 3.4, Copyright (C) 1989 Free Software Foundation, Inc.
  65. Omron Version 1.0, August 1, 1990.
  66. There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
  67. GDB is free software and you are welcome to distribute copies of it
  68.  under certain conditions; type "info copying" to see the conditions.
  69. Reading symbol data from /afs/cs.cmu.edu/misc/perl/build/src/perl-4.035/perl...done.
  70. Type "help" for a list of commands.
  71. (gdb) run -D14 foo
  72. Starting program: /afs/cs.cmu.edu/misc/perl/build/src/perl-4.035/perl -D14 foo
  73.  
  74. EXECUTING...
  75.  
  76. 5   mortals = (-1/-1) stack, = (-1/-1)
  77. 1   EXPR    (8a9c0)    r8a940    t0    a0    n0    cs0
  78. 1   E! SUBR (8a940) 2 args:
  79. 1   E! S: 1.NULL = ''
  80. 1   E! S: 2.NULL = ''
  81. 1   E! S: mortals = (-1/-1) stack, = (0/0)
  82. 3   E! S: EXPR    (8aec0)    r8ae80    t0    a0    n0    cs0
  83. 3   E! S: E! ASSIGN (8ae80) 2 args:
  84. 3   E! S: E! A: 1.LEXPR =>
  85. 3   E! S: E! A: LIST (8ad00) 2 args:
  86. 3   E! S: E! A: L: 1.LVAL $a = ''
  87. 3   E! S: E! A: L: 2.LVAL $b = ''
  88. 3   E! S: E! A: LIST RETURNS 2 ARGS ("","")
  89. 3   E! S: E! A: 1.LEXPR = ''
  90. 3   E! S: E! A: 2.EXPR =>
  91. 3   E! S: E! A: SUBR (8ae40) 2 args:
  92. 3   E! S: E! A: S: 1.NULL = ''
  93. 3   E! S: E! A: S: 2.EXPR =>
  94. 3   E! S: E! A: S: LIST (8adc0) 2 args:
  95. 3   E! S: E! A: S: L: 1.SINGLE = ''
  96. 3   E! S: E! A: S: L: 2.SINGLE = ''
  97. 3   E! S: E! A: S: LIST RETURNS 2 ARGS ("","")
  98. 3   E! S: E! A: S: 2.EXPR = ''
  99. Reading in symbols for cmd.c...done.
  100.  
  101. Program received signal 10, Bus error
  102. 0x3054 in savelist (sarg=(struct string **) 0x0, maxsarg=3) (cmd.c line 1165)
  103. 1165    }
  104. (gdb) where
  105. #0  0x3054 in savelist (sarg=(struct string **) 0x0, maxsarg=3) (cmd.c line 1165)
  106. Reading in symbols for doarg.c...done.
  107. #1  0xb998 in do_subr (arg=(struct arg *) 0x8ae40, gimme=1, arglast=(int *) 0xffbff2a0) (doarg.c line 1156)
  108. Reading in symbols for eval.c...done.
  109. #2  0x1b310 in eval (arg=(struct arg *) 0x8ae40, gimme=1, sp=393216) (eval.c line 1286)
  110. #3  0x174b8 in eval (arg=(struct arg *) 0x8ae80, gimme=0, sp=393216) (eval.c line 162)
  111. #4  0x1f40 in cmd_exec (cmdparm=(struct cmd *) 0x8aec0, gimme=0, sp=-1) (cmd.c line 654)
  112. #5  0xb9a8 in do_subr (arg=(struct arg *) 0x8ae40, gimme=1, arglast=(int *) 0xffbff2a0) (doarg.c line 1158)
  113. #6  0x1b310 in eval (arg=(struct arg *) 0x8a940, gimme=0, sp=393216) (eval.c line 1286)
  114. #7  0x1f40 in cmd_exec (cmdparm=(struct cmd *) 0x8a9c0, gimme=0, sp=-1) (cmd.c line 654)
  115. Reading in symbols for perl.c...done.
  116. #8  0x21c34 in main (argc=2, argv=(char **) 0x60000, env=(char **) 0x1) (perl.c line 890)
  117. #9  0x98 in start ()
  118. (gdb) quit
  119. The program is running.  Quit anyway? (y or n) y
  120. SHELL> exit
  121.  
  122. script done on Sun Aug 16 15:41:27 1992
  123.  
  124. The damage seems to be in doarg.c (do_subr):
  125.  
  126.         sub->depth++;
  127.         if (sub->depth >= 2) {  /* save temporaries on recursion? */
  128.             if (sub->depth == 100 && dowarn)
  129.                 warn("Deep recursion on subroutine \"%s\"",stab_ename(stab));
  130.             savelist(sub->tosave->ary_array,sub->tosave->ary_fill);
  131.         }
  132.  
  133. That sub->tosave->ary_array in the last line is null.
  134.