473,602 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange seg fault

Hi,

Recently some people I know stumbled upon a strange problem with the
following piece of code. This is reduced as far as possible.

The idea of the code is simple. There are four structs of which one
contains the other three structs. If we allocate a large double array
of that struct and try to initialize it to zero, or try to use one of
them in a function. The program gives a seg fault. If we make the array
slightly smaller, there is no problem. The problem only appears on
x86_64 architectures.

Below I past a copy of the failing code. If DATAMAX is set to 4820 the
program works, if it is set to 4830 it seg faults.

What could the reason be of this? We have calculated the amount of
memory and we have for sure no problem with that. A backtrace also does
not give any deeper insight.

Thanks for the help

#define DATAMAX 4830
#define ISOMAX 7

typedef struct
{
short iso;
char observable[15];
short ds_dt;
short ds_du;
double emin;
double emax;
double cos;
double ampli;
double error;
short tch;
} Photo;

typedef struct
{
short iso;
char observable[15];
short ds_dt;
double qsquared;
double s;
short cos_ang;
double t;
double cos;
double ampli;
double error;
short tch;
short beam_ener_input ;
double e_beam_ener;
double eps;
short cs_convention;
} Electro;
typedef struct
{
short iso;
char observable[10];
double pk;
double cos;
double ampli;
double ratio;
double error;
} Kaoncap;

typedef struct
{
short iso;
short photo_prod;
short electro_prod;
short kaoncapture;
Photo photo;
Electro elec;
Kaoncap kaoncap;
} Data;

int test(Data blub) {
return 0;
}

int main(int argc, char* argv)
{
// WORKS ALWAYS
Data datapoints[ISOMAX][DATAMAX];

// FAILS WITH DATAMAX = 4830 or larger
// Data datapoints[ISOMAX][DATAMAX] = {{{0}}};

// FAILS WITH DATAMAX = 4830 or lager
// Data datapoints[ISOMAX][DATAMAX];
// test(datapoints[0][0]);

return 0;
}
Feb 6 '08 #1
3 1385
On Feb 6, 1:17*pm, ciccio <no_valid_em... @spam.comwrote:
[snip]
int main(int argc, char* argv)
{
* // WORKS ALWAYS
* Data datapoints[ISOMAX][DATAMAX];

* // FAILS WITH DATAMAX = 4830 or larger
* // Data datapoints[ISOMAX][DATAMAX] = {{{0}}};

* // FAILS WITH DATAMAX = 4830 or lager
* // Data datapoints[ISOMAX][DATAMAX];
* // test(datapoints[0][0]);
<JohnCleeseVoic e>How much stack?</voice>

How big is your stack? What does your app do, or what
options does your development platform set, when that
happens?

If I did the math right, with DATAMAX of 4830 you've
got something in the range of 8MB. Default stack size
is usually not that large on most compilers.

Try allocating it through new rather than as an auto var.
Socks
Feb 6 '08 #2
On Feb 6, 7:57 pm, Puppet_Sock <puppet_s...@ho tmail.comwrote:
On Feb 6, 1:17 pm, ciccio <no_valid_em... @spam.comwrote:
[snip]
int main(int argc, char* argv)
{
// WORKS ALWAYS
Data datapoints[ISOMAX][DATAMAX];
// FAILS WITH DATAMAX = 4830 or larger
// Data datapoints[ISOMAX][DATAMAX] = {{{0}}};
// FAILS WITH DATAMAX = 4830 or lager
// Data datapoints[ISOMAX][DATAMAX];
// test(datapoints[0][0]);
<JohnCleeseVoic e>How much stack?</voice>
How big is your stack? What does your app do, or what
options does your development platform set, when that
happens?
If I did the math right, with DATAMAX of 4830 you've
got something in the range of 8MB. Default stack size
is usually not that large on most compilers.
The maximum stack size can often be set by a command at runtime.
On my system, it's 8MB by default, but I can always do "ulimit
-s unlimited", and use all of the available memory.

Not that that's necessarily a good idea. The reason why the
stack size is limited is so that an endless recursion will crash
in a reasonable time, rather than running for days eating up
machine resources. In this case, he should simple use an
std::vector, and be done with it.
Try allocating it through new rather than as an auto var.
Yes, but not manually, please.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Feb 7 '08 #3
Hi all,

Thanks for the info, this was indeed the case. I forgot about the stack.
Feb 8 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1931
by: Mal | last post by:
Greetings. I have a perplexing problem....please help. I am having a problem with an insert query. (SQL below) When I run the query via code (executing the SQL string) it crashes Access and gives me a Page Fault error in OLEAUT32.dll When I run the query from the query window it gives the normal "You are about to run an action query..." then appears to run, yet DOES NOT
3
1813
by: Keith E. Sauvant | last post by:
A behaviour we don't understand: +++ $user = 'xxx'; $password = 'xxx'; $database = 'xxx.xxx'; $query = 'SELECT 1 FROM DUAL'; $link = OCIlogon($user, $password, $database);
11
1959
by: junw2000 | last post by:
The following code can be compiled. But When I run it, it causes "Segmentation fault". #include <iostream> int main(){ char **c1; *c1 = "HOW"; // LINE1
13
1970
by: tomy | last post by:
Hi all: There is an amazing coredump in my C code, I was thinking it over and over... The code is simple as below: //************************************* const unsigned long int len = 102400000; int array; unsigned long int i;
7
2084
by: Tim Evers | last post by:
Hi, though I'm some kind of experienced bug-hunter :) I have no idea what happens in the following case: linux system, apache w. suexec, perl, graphviz (2.8). A perl script calls the graphviz binary. This works perfectly in a console but fails with a segfault when called under Apache/mod_cgi/perl regardsless of suexec beeing active or not. All Apache limits are off,
8
2574
by: gypsy3001 | last post by:
I inherited some code and got a segmentation fault on the following line: unsigned short localImage; It's really baffling and I can't think of what could cause this problem. The following are debug code I inserted: cerr << "unsigned short size: " << sizeof (unsigned short) << endl; cerr << "panelRows: " << panelRows << endl;
5
3499
by: Jeff | last post by:
Okay, I'm still new to vb.net 2005 - throught this was a hardware problem, but now I don't know. (I'm having some problem with my newgroup provider, so hopefully this will go through) This problem just started about a week ago, before all was fine. I'm using the code below to access a mysql database. On the line indicated when the connection is opened, the application has been sporatically drawing an error. It doesn't occur very often -...
2
1329
by: Jeff | last post by:
Hey In VS2005 I've copied some text to the clipboard, but when I paste it, I get something I previuosly added to the clipboard. I thought a reboot of my computer would help, but it didn''t.... after this problem occured, I've done a test where I copyed text from TextPad to vs2005 and that works. - but after this test, I again tryed to copy & paste within vs2005, but vs2005 pastes something I've previously
4
1215
by: kj | last post by:
I'm running into a strange seg fault with the module cjson. The strange part is that it does not occur when I run the code under Emacs' Pydb. Here's an example: import sys, cjson d1 = {'a': 1, 'b': 2, 'c': 3}
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.