Why does this segfault, big struct: too big?

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

 



When I compile the following code I get a strange intermittent segfault.

Compiling with

gcc -lm -O -Wall mk2.c -o mk2

Case 1)  Pbars = 400,  final "printf" statement present -> No seg fault,
GDB says exits with code 04
Case 2)  Pbars = 500,  final "printf" statement present -> Seg faults

Program received signal SIGSEGV, Segmentation fault.
0x0804841c in main (argc=1, argv=0xbfffdc44) at 2dhistomk2.c:43
43         printf("junk");

Case 3) Pbars >= 500, final "printd" statement NOT present -> NO seg
fault,  GDB says exits with code 01

This fault occurs as part of a longer code,  the printf statement triggers
the problem as do other calls like "srand48(0)"

I can't imagine why the size of a struct is important and why these
statements would trigger this.  Everything seems to be linked OK, with a
lower value of Pbars full code does exactly what it should do.

OH Yeah

gcc -v, gives me

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-113)

Yours very confused

Jack Liddle
Theoretical Physics
University Of Oxford

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>


//Adjust these for your run
#define Sbars 440
#define Smin 875
#define Smax 985

#define Pmin 0
#define Pmax 2
#define Pbars 400

#define Nblocks 20


struct histogrambar
{
  double Sstart;
  double Sfinish;
  double Pstart;
  double Pfinish;
  double number;


};
typedef struct histogrambar Histogrambar;

struct histogram
{
  struct histogrambar bar[Sbars][Pbars];
};

typedef struct histogram Histogram;


int main(int  argc,char **argv)
{
   Histogram hist;
   printf("junk");
}





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux