LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Need help about Segmentation fault (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/need-help-about-segmentation-fault-811396/)

ligang 06-01-2010 12:08 AM

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;
}


paulsm4 06-01-2010 12:23 AM

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

ligang 06-01-2010 01:32 AM

Thanks! PSM
 
Quote:

Originally Posted by paulsm4 (Post 3988152)
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


All times are GMT -5. The time now is 10:13 PM.