Graphviz Issue Tracker
Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001252graphvizGraph Librariespublic2008-01-28 09:172011-04-28 04:03
ReporterAlexander Fairley 
Assigned Tonorth 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSx86-Linux-FC8 Kernel 2.6.23OS Version
Summary0001252: Modifying parsed cgraph graphs induces a segfault
Description



Hi there,



While writing tests for my wrapper for libcgraph, I came across a
curious phenomenon. It seems that attempting to add vertices/edges to
graphs parsed by agread leads to a segfault, wheras graphs created by
a call to agopen don't exhibit this behavior. I've attached a short
piece of code demonstrating this. I can work around this, with no
real problems at all, but I'm curious as to what the actual cause of
the segfault is. Does it have to do with flex/bison stuff, or is it a
specific design decision? It looks to me as though the various graph
modification functions(agnode, agedge) are implemented in terms of
functions defined in grammar.c, so I'm a bit puzzled as to what the
underlying memory situation is that causes the segfault.



Regards,



Alex



<CD>
**********************************************************************
***** code demonstrating segfault: ****
**********************************************************************
#include<string.h>
#include<check.h>
#include<stdlib.h>
#include <graphviz/cgraph.h>
#include <stdio.h>



Agraph_t *g1, *g2;
char *filename = "graph1.dot";
char *vertexNames[5] = {"A","B","C","D",
                       /*E added as part of Test_Graph_Write*/
                       "E"};
int edgeIndices[5][2] = {{0,1},{1,2},{1,3},
                        {4,2},{4,3} };
Agnode_t *vertices[5];



int main() {
 int i;
 FILE *ifp = fopen(filename, "r");
 //Initialize g1 based on a parsed file, g2 from scratch
 g1 = agread(ifp,NULL);
 g2 = agopen("Modifiable", Agdirected, NULL);
 //Populate g2 with no problems
 for(i = 0; i < 5; i++){
   agnode(g2, vertexNames[i], TRUE);
 }
 for(i =0; i < 5; i++){
   int *indx = edgeIndices[i];
   agedge(g2,vertices[indx[0]],vertices[indx[1]],NULL,TRUE);
 }
 //Attempt to add a vertex to g1, observe a segfault.
 agnode(g1,"E", TRUE);
 return 0;



}
</CD>
Steps To Reproduce

digraph Random {
       L [color=red];
       L -> N;
       E [color=red];
       E -> N;
       E -> I;
       B [color=red];
       B -> N;
       B -> L;
       M [color=red];
       M -> N;
       H [color=red];
       H -> K;
       H -> J;
       F [color=red];
       F -> J;
       C [color=red];
       C -> I;
       A [color=red];
       A -> H;
       A -> F;
       A -> I;
       D [color=red];
       D -> E;
       D -> G;
}
Additional Information

[north] Programmer error: the vertices[] array is never initialized,
so it causes a fault when used in agedge().
TagsNo tags attached.
AUXILLARY-FILES
DATE-FIXED
FIX-COMMENT
FORMER-ID1284
INPUT-FILE
OUTPUT-FILE
STATUS-COMMENTFixed (28 Jan 2008)
VERSION     2.16
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2011-04-28 04:03 user1 New Issue
2011-04-28 04:03 user1 Assigned To => Stephen North


MantisBT 1.2.5[^]
Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker