From: Jack Liddle <j.liddle1@physics.ox.ac.uk>
To: gcc-help@gcc.gnu.org
Subject: Why does this segfault, big struct: too big?
Date: Mon, 06 Sep 2004 12:47:00 -0000 [thread overview]
Message-ID: <Pine.GSO.4.53.0409061336500.20110@apollo> (raw)
In-Reply-To: <1094473544.413c57486f286@imp5-q.free.fr>
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");
}
next prev parent reply other threads:[~2004-09-06 12:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-06 12:25 static instanciation in libraries stripped by the linker kadreg
2004-09-06 12:47 ` Jack Liddle [this message]
2004-09-07 12:33 ` Why does this segfault, big struct: too big? Eljay Love-Jensen
2004-09-07 13:04 ` static instanciation in libraries stripped by the linker Eljay Love-Jensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.GSO.4.53.0409061336500.20110@apollo \
--to=j.liddle1@physics.ox.ac.uk \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).