home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / utils / bug / 2346 < prev    next >
Encoding:
Text File  |  1993-01-08  |  4.7 KB  |  177 lines

  1. Newsgroups: gnu.utils.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!banzai.pcc.COM!jay
  3. From: jay@banzai.pcc.COM (Jay Schuster)
  4. Subject: Make-3.62 rules bug (with fix)
  5. Message-ID: <C0Hs0G.KEx@banzai.PCC.COM>
  6. Summary: singly linked list deletion code incorrect
  7. Sender: gnulists@ai.mit.edu
  8. Organization: The People's Computer Company, Williston, VT
  9. Distribution: gnu
  10. Date: Thu, 7 Jan 1993 16:23:44 GMT
  11. Approved: bug-gnu-utils@prep.ai.mit.edu
  12. Lines: 163
  13.  
  14. Make-3.62 was dumping core on me with a complicated Makefile
  15. on an IBM RS/6000 running IBM AIX 3.2.  In tracing it down,
  16. a problem similar to that that I had with vpath was happenning
  17. when rules were being deleted out of the list.
  18.  
  19. There was also a problem with my earlier vpath fix, in that it
  20. referenced vpath->next when vpath may have just been free()'d.
  21. (This was also a problem with the existing rule.c code).
  22.  
  23. This patch incorporates the vpath fix I posted yesterday, along
  24. with a fix to it, and the fix to the rule.c.
  25.  
  26. --- ./rule.c~    Wed Jan  6 18:11:39 1993
  27. +++ ./rule.c    Thu Jan  7 11:21:28 1993
  28. @@ -65,13 +65,14 @@
  29.  {
  30.    char *name;
  31.    unsigned int namelen;
  32. -  register struct rule *rule, *lastrule;
  33. +  register struct rule *rule, *lastrule, *nextrule;
  34.  
  35.    num_pattern_rules = 0;
  36.    
  37.    name = 0;
  38.    namelen = 0;
  39. -  rule = lastrule = pattern_rules;
  40. +  rule = pattern_rules;
  41. +  lastrule = NULL;
  42.    while (rule != 0)
  43.      {
  44.        unsigned int ndeps = 0;
  45. @@ -108,7 +109,8 @@
  46.          {
  47.            if (*name == '/')
  48.              {
  49. -              freerule (rule, lastrule);
  50. +              nextrule = rule->next;
  51. +              freerule (rule, lastrule, 1);
  52.                rule = lastrule;
  53.                goto end_main_loop;
  54.              }
  55. @@ -121,9 +123,11 @@
  56.        if (ndeps > max_pattern_deps)
  57.      max_pattern_deps = ndeps;
  58.  
  59. +      nextrule = rule->next;
  60. +
  61.      end_main_loop:;
  62.        lastrule = rule;
  63. -      rule = rule->next;
  64. +      rule = nextrule;
  65.      }
  66.    
  67.    if (name != 0)
  68. @@ -251,7 +255,7 @@
  69.    rule->next = 0;
  70.  
  71.    /* Search for an identical rule.  */
  72. -  lastrule = pattern_rules;
  73. +  lastrule = NULL;
  74.    for (r = pattern_rules; r != 0; lastrule = r, r = r->next)
  75.      for (i = 0; rule->targets[i] != 0; ++i)
  76.        for (j = 0; r->targets[j] != 0; ++j)
  77. @@ -267,7 +271,7 @@
  78.            if (override)
  79.          {
  80.            /* Remove the old rule.  */
  81. -          freerule (r, lastrule);
  82. +          freerule (r, lastrule, 1);
  83.            /* Install the new one.  */
  84.            if (pattern_rules == 0)
  85.              pattern_rules = rule;
  86. @@ -281,7 +285,7 @@
  87.            else
  88.          {
  89.            /* The old rule stays intact.  Destroy the new one.  */
  90. -          freerule (rule, (struct rule *) 0);
  91. +          freerule (rule, (struct rule *) 0, 0);
  92.            return 0;
  93.          }
  94.        }
  95. @@ -357,11 +361,14 @@
  96.  
  97.  /* Free all the storage used in RULE and take it out of the
  98.     pattern_rules chain.  LASTRULE is the rule whose next pointer
  99. -   points to RULE.  */
  100. +   points to RULE.  DELETE should be zero to prevent the deletion
  101. +   of RULE from the pattern_rules list (in which case LASTRULE is
  102. +   ignored) */
  103.  
  104.  static void
  105. -freerule (rule, lastrule)
  106. +freerule (rule, lastrule, delete)
  107.       register struct rule *rule, *lastrule;
  108. +     int delete;
  109.  {
  110.    struct rule *next = rule->next;
  111.    register unsigned int i;
  112. @@ -386,14 +393,11 @@
  113.  
  114.    free ((char *) rule);
  115.  
  116. -  if (lastrule == 0)
  117. +  if (!delete)
  118.      return;
  119.  
  120. -  if (pattern_rules == rule)
  121. -    if (lastrule != pattern_rules)
  122. -      abort ();
  123. -    else
  124. -      pattern_rules = next;
  125. +  if (lastrule == 0)
  126. +    pattern_rules = next;
  127.    else
  128.      lastrule->next = next;
  129.    if (last_pattern_rule == rule)
  130. --- ./vpath.c~    Wed Jan  6 18:11:39 1993
  131. +++ ./vpath.c    Thu Jan  7 10:57:22 1993
  132. @@ -122,10 +122,11 @@
  133.    if (dirpath == 0)
  134.      {
  135.        /* Remove matching listings.  */
  136. -      register struct vpath *path, *lastpath;
  137. +      register struct vpath *path, *lastpath, *nextpath;
  138.  
  139. -      lastpath = vpaths;
  140. -      for (path = vpaths; path != 0; lastpath = path, path = path->next)
  141. +      lastpath = NULL;
  142. +      path = vpaths;
  143. +      while (path != 0)
  144.      if (pattern == 0
  145.          || (((percent == 0 && path->percent == 0)
  146.           || (percent - pattern == path->percent - path->pattern))
  147. @@ -132,15 +133,22 @@
  148.          && streq (pattern, path->pattern)))
  149.        {
  150.          /* Remove it from the linked list.  */
  151. -        if (lastpath == vpaths)
  152. -          vpaths = path->next;
  153. +        nextpath = path->next;
  154. +        if (lastpath == NULL)
  155. +          vpaths = nextpath;
  156.          else
  157. -          lastpath->next = path->next;
  158. +          lastpath->next = nextpath;
  159.  
  160.          /* Free its unused storage.  */
  161.          free (path->pattern);
  162.          free ((char *) path->searchpath);
  163.          free ((char *) path);
  164. +        path = nextpath;
  165. +      }
  166. +    else
  167. +      {
  168. +        lastpath = path;
  169. +        path = path->next;
  170.        }
  171.        if (pattern != 0)
  172.      free (pattern);
  173. -- 
  174. Jay Schuster <jay@pcc.COM>    uunet!uvm-gen!banzai!jay, attmail!banzai!jay
  175. The People's Computer Company    `Revolutionary Programming'
  176.  
  177.