[Nauty-list] Segmentation fault with readg()

Tristan Miller psychonaut at nothingisreal.com
Mon Jun 10 02:31:57 EST 2013


Greetings.

In 2011, a subscriber to this list asked how to read in the graphs produced 
by geng.  William Rummler's answer 
<http://dcsmail.anu.edu.au/pipermail/nauty-list/2011-January/000582.html> 
advised the subscriber to use the opengraphfile() and readg() functions 
from gtools.h; I quote the example code below.  I tried compiling and 
running this code but the output doesn't seem to correspond to the given 
graph, and moreover it seems it always crashes with a segmentation fault on 
the second call to readg():


$ gcc -o readgraph readgraph.c nauty.a
$ geng 3 1:0 | ./readgraph
 0 0 0
 0 0 0
 0 0 0

Segmentation fault


Is there some bug in the example (or in nauty itself), or am I doing 
something wrong?


Here's the example code originally posted by William Rummler:

#define MAXN 30
#include "gtools.h"

int
main( void )
{
  /*
   * Variables for using with opengraphfile() and readg()
   */
  FILE *f;
  graph g[ MAXN * MAXM ];
  int codetype, m, n;

  /*
   * Example:
   * Reading graphs from standard input and printing their adjacency 
matrices
   */
  set *v;
  int i, j;
  f = opengraphfile( NULL, &codetype, 0, 0 );
  while( readg( f, g, 0, &m, &n ) )
    {
      for ( i = 0; i < n; ++i )
        {
          v = GRAPHROW( g, i, m );
          for ( j = 0; j < n; ++j )
            {
              printf( " %d", ISELEMENT( v, j ) ? 1 : 0 );
            }
          printf( "\n" );
        }
      printf( "\n" );
    }
  return 0;
}

Regards,
Tristan

-- 
   _
  _V.-o         Tristan Miller          ><  Space is limited
 / |`-'  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-  <>  In a haiku, so it's hard
(7_\\    http://www.nothingisreal.com/  ><  To finish what you
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://mailman.anu.edu.au/mailman/private/nauty/attachments/20130609/b023b884/attachment.bin 


More information about the Nauty mailing list