LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-29-2010, 06:57 PM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,397

Rep: Reputation: 81
hitting size limit (or whatever), gcc


Hya,

I am inventing wheel here. If anybody else is hitting similar problem, hopefully this post helps.

I am sure that this is some sort of size limit related. The code below compiles, but runs into SegFault.

Code:
int main(int argc, char** argv, char** envv){

struct  rStr {
        long    i1l;
        long    i2l;
        long    j1l;
        long    j2l;
        int     k1;
        char    s1[400];
        char    s2[400];
        char    s3[50];
        }       qu[10000];

return;
}
When array size of "qu" is small (100 ish), it runs. If memory is allocated dynamically using pointer and malloc, it runs also. I guess the problem is not physical memory related.

My system is Debian squeeze, gcc version 4.4.5 (Debian 4.4.5-8). It took quite a while for me to figure out, so I am posting here.

Happy Penguins!
 
Old 11-29-2010, 06:59 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,397

Original Poster
Rep: Reputation: 81
Self reply,

If anybody knows how to detect this problem, please post here.
 
Old 11-29-2010, 07:53 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Try compiling with "-fstack-check" and see what happens:

http://gcc.gnu.org/onlinedocs/gcc/Co...de-Gen-Options

And/or "-fstack-protector-all":

http://gcc.gnu.org/onlinedocs/gcc/Op...timize-Options

'Hope that helps
 
Old 11-30-2010, 07:48 AM   #4
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,965

Rep: Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073
The problem is stack overflow.

Quote:
Originally Posted by kaz2100 View Post
If anybody knows how to detect this problem, please post here.
Are you really asking how to detect the stack overflow (I expect paulsm4's post covers that)?

Or do you want to correct the stack overflow? You can use the ulimit command to change the initial stack size.
 
Old 11-30-2010, 10:42 PM   #5
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,397

Original Poster
Rep: Reputation: 81
Hya,

Thanks for replies, however...
Code:
>cat error.c
int main(int argc, char** argv, char** envv){

struct  rStr {
        long    i1l;
        long    i2l;
        long    j1l;
        long    j2l;
        int     k1;
        char    s1[400];
        char    s2[400];
        char    s3[50];
        }       qu[10000];

return;
}
>gcc -fstack-check error.c 
>./a.out
Segmentation fault
>gcc -fstack-protector-all error.c
0 /common/ref18>./a.out
Segmentation fault
>gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
I think ulimit is a bash built-in command and I use tcsh.

I would prefer using pointer to using getrlimit(), setrlimit() and sysconf(). At least, I know where to check next time.

Thanks again.

Happy Penguins!
 
  


Reply

Tags
array, gcc, segfault, size


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
limit a forder size kernelvn Fedora 1 04-23-2005 02:50 AM
~/ size limit bm1 Slackware 5 09-23-2004 07:10 AM
Pty's -- Hitting Limit! zepplin611 AIX 2 03-09-2004 08:48 AM
2.1 Gb size limit?? pk21 Linux - General 5 08-30-2003 02:40 PM
Size limit? pyropenguin Linux - Networking 1 12-18-2002 12:48 PM


All times are GMT -5. The time now is 07:35 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration