bug-cflow
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-cflow] cflow-1.1 doesn't find main


From: Sergey Poznyakoff
Subject: Re: [Bug-cflow] cflow-1.1 doesn't find main
Date: Thu, 07 Sep 2006 18:25:16 +0300

Robert E. Michael <address@hidden> wrote:

>     Yet when I run it on quite a few of my own programs, the "main"
> routine does not show up in the output.  A terse example is
> attached.

It is a bug in cflow: it was confused by k&r function declarations.
Please find attached a patch that fixes it. 

> When I run it on much larger examples, it gets a
> segmentation fault.  What is going on?

Possibly this is due to another bug, discovered yesterday.  I have sent
the corresponding patch to the list yesterday.  Just in case, I am
resending it with this message (see atachment 2.)

Please, inform me if it works for you.

Regards,
Sergey

Index: src/parser.c
===================================================================
RCS file: /cvsroot/cflow/cflow/src/parser.c,v
retrieving revision 1.35
diff -p -u -r1.35 parser.c
--- src/parser.c        15 Mar 2006 19:32:34 -0000      1.35
+++ src/parser.c        7 Sep 2006 15:17:06 -0000
@@ -30,13 +30,13 @@ typedef struct {
 void parse_declaration(Ident*, int);
 void parse_variable_declaration(Ident*, int);
 void parse_function_declaration(Ident*, int);
-void parse_dcl(Ident*);
+void parse_dcl(Ident*, int maybe_knr);
 void parse_knr_dcl(Ident*);
 void parse_typedef();
 void expression();
 void initializer_list();
 void func_body();
-void declare(Ident*);
+void declare(Ident*, int maybe_knr);
 void declare_type(Ident*);
 int dcl(Ident*);
 int parmdcl(Ident*);
@@ -540,7 +540,7 @@ parse_variable_declaration(Ident *ident,
          }
      }
  again:
-     parse_dcl(ident);
+     parse_dcl(ident, 0);
      
  select:    
      switch (tok.type) {
@@ -613,58 +613,7 @@ void
 parse_knr_dcl(Ident *ident)
 {
      ident->type_end = -1;
-     parse_dcl(ident);
-     if (strict_ansi)
-         return;
-     
-     switch (tok.type) {
-     case IDENTIFIER:
-     case TYPE:
-     case STRUCT:
-         if (ident->parmcnt >= 0) {
-              /* maybe K&R function definition */
-              int parmcnt, stop;
-              Stackpos sp, new_sp;
-              Ident id;
-              
-              mark(sp);
-              parmcnt = 0;
-              
-              for (stop = 0; !stop && parmcnt < ident->parmcnt;
-                   nexttoken()) {
-                   id.type_end = -1;
-                   switch (tok.type) {
-                   case LBRACE:
-                   case LBRACE0:
-                        putback();
-                        stop = 1;
-                        break;
-                   case TYPE:
-                   case IDENTIFIER:
-                   case STRUCT:
-                        putback();
-                        mark(new_sp);
-                        if (dcl(&id) == 0) {
-                             parmcnt++;
-                             if (tok.type == ',') {
-                                  do {
-                                       tos = id.type_end; /* ouch! */
-                                       restore(new_sp);
-                                       dcl(&id);
-                                  } while (tok.type == ',');
-                             } else if (tok.type != ';')
-                                  putback();
-                             break;
-                        }
-                        /* else */
-                        /* FALLTHRU */
-                   default:
-                        restore(sp);
-                        return;
-                   }
-              }
-         }
-     }
+     parse_dcl(ident, !strict_ansi);     
 }
 
 void
@@ -717,7 +666,7 @@ parse_typedef()
 }
 
 void
-parse_dcl(Ident *ident)
+parse_dcl(Ident *ident, int maybe_knr)
 {
      ident->parmcnt = -1;
      ident->name = NULL;
@@ -725,7 +674,7 @@ parse_dcl(Ident *ident)
      dcl(ident);
      save_stack();
      if (ident->name)
-         declare(ident);
+         declare(ident, maybe_knr);
      else 
          undo_save_stack();
 }
@@ -947,8 +896,61 @@ func_body()
      }
 }
 
+int
+get_knr_args(Ident *ident)
+{
+     int parmcnt, stop;
+     Stackpos sp, new_sp;
+     Ident id;
+
+     switch (tok.type) {
+     case IDENTIFIER:
+     case TYPE:
+     case STRUCT:
+         /* maybe K&R function definition */
+         
+         mark(sp);
+         parmcnt = 0;
+         
+         for (stop = 0; !stop && parmcnt < ident->parmcnt;
+              nexttoken()) {
+              id.type_end = -1;
+              switch (tok.type) {
+              case LBRACE:
+              case LBRACE0:
+                   putback();
+                   stop = 1;
+                   break;
+              case TYPE:
+              case IDENTIFIER:
+              case STRUCT:
+                   putback();
+                   mark(new_sp);
+                   if (dcl(&id) == 0) {
+                        parmcnt++;
+                        if (tok.type == ',') {
+                             do {
+                                  tos = id.type_end; /* ouch! */
+                                  restore(new_sp);
+                                  dcl(&id);
+                             } while (tok.type == ',');
+                        } else if (tok.type != ';')
+                             putback();
+                        break;
+                   }
+                   /* else */
+                   /* FALLTHRU */
+              default:
+                   restore(sp);
+                   return 1;
+              }
+         }
+     }
+     return 0;
+}
+
 void
-declare(Ident *ident)
+declare(Ident *ident, int maybe_knr)
 {
      Symbol *sp;
      
@@ -965,8 +967,10 @@ declare(Ident *ident)
          sp->arity = -1;
          return;
      } 
-     
-     if ((ident->parmcnt >= 0 && !(tok.type == LBRACE || tok.type == LBRACE0))
+
+     if ((ident->parmcnt >= 0
+         && (!maybe_knr || get_knr_args(ident) == 0)
+         && !(tok.type == LBRACE || tok.type == LBRACE0 || tok.type == TYPE))
         || (ident->parmcnt < 0 && ident->storage == ExplicitExternStorage)) {
          undo_save_stack();
          /* add_external()?? */
Organization: Err, what do you mean?
To: <address@hidden>
From: "Sergey Poznyakoff" <address@hidden>
Date: Wed, 06 Sep 2006 18:26:32 +0300
Subject: Re: [Bug-cflow] seg. fault with 'cflow -ix^s ' options
X-Mailer: MH-E 7.84+cvs; GNU Mailutils 1.0; GNU Emacs 21.3.2
Cc: address@hidden, address@hidden
Sender: address@hidden

<address@hidden> wrote:

> Just to repport that the last GNU cflow (1.1) raises a segmentation fault 
> if used with following option on cflow 1.1 source code
> 
> cflow -ix^s cflow-1.1/src/*.c

Thank you.  Here is the patch:

Index: src/symbol.c
===================================================================
RCS file: /cvsroot/cflow/cflow/src/symbol.c,v
retrieving revision 1.17
diff -p -u -r1.17 symbol.c
--- src/symbol.c        15 Mar 2006 19:33:01 -0000      1.17
+++ src/symbol.c        6 Sep 2006 15:25:45 -0000
@@ -107,7 +107,9 @@ unlink_symbol(struct table_entry *tp)
 static void
 delete_symbol(struct table_entry *tp)
 {
-     free(unlink_symbol(tp));
+     Symbol *s = unlink_symbol(tp);
+     if (s->ref_line == NULL) /* Symbol is not referenced */
+         free(s);
 }     
 
 static void cleanup_symbol_refs(Symbol *sym);


_______________________________________________
Bug-cflow mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-cflow

reply via email to

[Prev in Thread] Current Thread [Next in Thread]