LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices



Reply
 
Search this Thread
Old 06-01-2010, 01:08 AM   #1
ligang
LQ Newbie
 
Registered: Apr 2010
Posts: 13

Rep: Reputation: 1
Unhappy Need help about Segmentation fault


I can run this code in Linux PC. but after cross compilation and run it in ARM target board, i met Segmentation fault. I used GDB to check the traceback, but couldn't get the actual source line number.
How can i solve the segmentation fault.
Below is my operation:
1. cross compilation:
Code:
arm-linux-gcc -g -o test test.c
2. copy test to target
3. run
Code:
./test
Segmentation fault
4. debug
Code:
Program received signal SIGSEGV, Segmentation fault.
Cannot access memory at address 0x6e7a6974
5. source code
Code:
#include<stdio.h>
int main(void)
{
  char lg[64];
  char cmd[64]="1.1.1.1";
  sprintf(lg,"sed -i 's/2.2.2.2/%s/' /mnt/jffs2/ddns_var/named/gotowiznet.com.dns ",cmd);
  system (lg);
  return 0;
}

Last edited by ligang; 06-01-2010 at 01:18 AM.
 
Old 06-01-2010, 01:23 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Change "system(lg)" to "printf ("strlen (lg): %d\n", strlen (lg));"

... and you'll see the string happens to be 73+1 bytes (exceeding the 64 bytes you've allocated).

'Hope that helps .. PSM
 
1 members found this post helpful.
Old 06-01-2010, 02:32 AM   #3
ligang
LQ Newbie
 
Registered: Apr 2010
Posts: 13

Original Poster
Rep: Reputation: 1
Thanks! PSM

Quote:
Originally Posted by paulsm4 View Post
Hi -

Change "system(lg)" to "printf ("strlen (lg): %d\n", strlen (lg));"

... and you'll see the string happens to be 73+1 bytes (exceeding the 64 bytes you've allocated).

'Hope that helps .. PSM
Thanks! PSM
 
  


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 Sparcler Programming 16 09-26-2008 01:51 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 10:34 AM
Segmentation fault satimis Linux From Scratch 4 07-11-2005 09:01 PM
segmentation fault itywygms Linux - Newbie 10 09-19-2004 09:25 PM
Segmentation fault.... lokizen Linux - Newbie 7 09-14-2004 01:40 AM


All times are GMT -5. The time now is 11:32 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration