LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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
  Search this Thread
Old 12-16-2013, 11:03 AM   #1
sirjase
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Rep: Reputation: Disabled
Segmentation fault (core dumped)


This is a "C" question,Which I'm new to:

Code:
#include <stdio.h>
#include <fenv.h>
/*#include <float.h>*/
/*#this program is a proof of concept. It will be used to:
#first create n^n for numbers 2-127 in binary
#second assign the binary of the numbers in an array "NthArray"*/

void main()
/*#loop to fill the array*/
{
     		int count;
		int i;
		long double res=1;
		long double NthArray[10];
     		for (count = 0; count <= 127; count++)
			{
				res=1;
				for (i=1; i <= count; i++)
					{
					/*printf ("i=%d\n",i );*/
      					res = res * count;
					/*printf ("res=%f\n",res );*/
					}
			NthArray[count] = res;
          		printf ("Count=%d",count );
			printf (".");
				printf ("The Nth = %Lf\n",NthArray[count]);
			
			}
res=1;printf("table loaded\n");
}
This bit of code complies fine but when I run it I get:
Quote:
Count=0.The Nth = 1.000000
Count=1.The Nth = 1.000000
Count=2.The Nth = 4.000000
Count=3.The Nth = 27.000000
Count=4.The Nth = 256.000000
Count=5.The Nth = 3125.000000
Count=6.The Nth = 46656.000000
Count=7.The Nth = 823543.000000
Count=8.The Nth = 16777216.000000
Count=9.The Nth = 387420489.000000
.................
Count=127.The Nth = 1524307411995722575737095034367932617400955458112824476089134616001097797110416587846022345778082377 2948777596941440497539534786314040488562210183714084842392119548923554743813133193657360180665611222 92345542412230225506634371181613735575034509047146723374175939985408.000000
table loaded
Segmentation fault (core dumped)
My debug looks like:
Quote:
gdb ./nth -c mydump.txt
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jason/Documents/programming/nth...done.
"/home/jason/Documents/programming/mydump.txt" is not a core dump: File format not recognized
(gdb) run
Starting program: /home/jason/Documents/programming/./nth
Count=0.The Nth = 1.000000
Count=1.The Nth = 1.000000
Count=2.The Nth = 4.000000
Count=3.The Nth = 27.000000
Count=4.The Nth = 256.000000
Count=5.The Nth = 3125.000000
Count=6.The Nth = 46656.000000
Count=7.The Nth = 823543.000000
Count=8.The Nth = 16777216.000000
Count=9.The Nth = 387420489.000000
Count=10.The Nth = 10000000000.000000
...............
Count=127.The Nth = 1524307411995722575737095034367932617400955458112824476089134616001097797110416587846022345778082377 2948777596941440497539534786314040488562210183714084842392119548923554743813133193657360180665611222 92345542412230225506634371181613735575034509047146723374175939985408.000000
table loaded

Program received signal SIGSEGV, Segmentation fault.
0x00004025 in ?? ()
(gdb)
I'm not sure why it doesn't like my back trace file. Since it point to an open "()"
I'm not sure where to go next. I have googled "0x00004025" to no avail, I'm sure it a simple error between the keyboard and the chair but I'm stuck, any Ideas?
 
Old 12-16-2013, 03:28 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 109Reputation: 109
Code:
...
		long double NthArray[10];
     		for (count = 0; count <= 127; count++)
...
And in that loop

Code:
			NthArray[count] = res;
Just gonna leave this here. Perhaps it might dawn on you.
 
1 members found this post helpful.
Old 12-16-2013, 03:50 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138
And if not, try compiling with -fbounds-check.
 
Old 12-16-2013, 07:12 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,588

Rep: Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894Reputation: 1894
Quote:
gdb ./nth -c mydump.txt
Coredump files are usually called just coredump, no extension. Also check that you have coredumps enabled (ulimit -c). Although if you can just run the program in the debugger and reproduce the error directly (like you've done), that's usually easier.

Your backtrace only has 1 frame in it, probably because your program has corrupted the stack so a backtrace cannot be constructed.

Also make sure to compile with debug information (pass -g to gcc), otherwise your backtraces will have only raw addresses, and no function names, or line numbers.
 
Old 12-17-2013, 10:01 AM   #5
sirjase
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Lightbulb Thank you,

orgcandman:
Hello captain obvious.
I guess if you're going to only set 10 vars in an array it's hard to stuff 128 into it.

Thanks for your help.
-Jase
 
Old 12-17-2013, 11:25 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,137

Rep: Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515
Why don't you see backtrace information?
Cos your stack is corrupted, that's why.
 
Old 12-17-2013, 09:54 PM   #7
sirjase
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Why don't you see backtrace information?
Cos your stack is corrupted, that's why.
Can you explain what you mean?
 
Old 12-18-2013, 04:29 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,137

Rep: Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515
For a start: https://en.wikipedia.org/wiki/Memory_corruption
 
Old 12-18-2013, 04:40 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,961

Rep: Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283Reputation: 5283
you may try to use valgrind to catch memory corruption.
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault (core dumped) mayankladoia Programming 4 07-17-2010 03:11 AM
segmentation fault (core dumped) - what??? Micro420 Programming 6 12-07-2006 02:03 AM
Segmentation fault (core dumped) eytan *BSD 3 04-27-2005 09:38 PM
Segmentation Fault (core dumped) newuser455 Linux - Software 3 08-28-2004 03:39 PM
Segmentation fault (core dumped) hasanaydin Linux - General 0 03-27-2002 08:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:42 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration