Hello everybody,
I've been working on a program on my Linux box, after finished the code, i compile it with gcc -Wall option, so i can see what's wrong or unused.
The Walll output shows nothing, so there are no loose ends on the program.
I run the program on my system, and it works PERFECTLY.
My problem is when i copy the source code of the program and compile it on other operating systems (Also Linux, but live versions). It compiles without any warnings from -Wall, but when i run the program, i get segmentation fault.
Since most live versions doesn't have gdb, i figured out which functions were causing the segmentation fault myself, and it is confusing, because simple lines like:
Are causing the segmentation violation.
I mean, the same code doesn't cause any segmentation fault or any other problem when running, but when i compile the code on other linux system (without warnings) and run it, it fails.
Does anybody know why this happens? Would it be a missing library, package, or something which my host has and the other one does not?
Segmentation faults come from the outside of the program most times, in the sense that somebody enters a nodename with 400 characters. Instead of your expected size.
In a live environment, you have to program defensively. All input is poison. Period.
Something that comes in as argv[1] probably means means it was entered on the command line. Check lengths of string arguments. Check to see that numbers entered as a string are in fact numbers. And are in the range expected. Test input for acceptance, never test it to exclude, because you can never outwit the idiots running your code.
For example, test argv[1] for length. Make sure argc shows the right number of arguments. Absolutely, positively check ALL return codes from any runtime library.
getaddrinfo() will reject garbage node names for you, for example. So a lot of the burden of testing to find good input can be passed off to well-tested code.
Just because a program compiles, does not make it correct in any way. You should actively try to break your code with simulated bad input during unit testing, for example.
Before you test for correct behavior with good input.
If you have identical runtime libraries on your dev and live systems you can copy the core file from over there and may be able to debug it. If it was compiled stripped this may be of no help.
That's what i don't understand, because in this case there are no idiots giving wrong or different arguments than expected to the program. If i run, let's say: ./a.out eth0 in my host it runs perfectly, but in a live environment, and compiled on it, i run it with the same arguments, (./a.out eth0 in our example) and i expect to get the same result, but instead i get segmentation fault.
So, it's not a user mistake, i think it has to be with a libraries factor, a missing package, i don't know. I remember compiling the code on an earlier version of Linux and gcc returning warnings and not producing an executable file. I mean, if the code is working, correct and functionable on 2.6,2 it should be equally correct on 2.6.1
sockaddr might be null or has been overwritten and is pointing to some odd location.
Won't matter in this case:
The sockaddr isn't an address - it's a structure, and the results of the strcpy() depend on long argv[1] is. It could segv, or not.
Now, the content of sa_data is almost certainly not expected to be in string format, though....
Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1...
I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one.
Below are two very condensed snippets of which I have added the results inside the each code section.
IMPORTANT!... (11 Replies)
I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this :
i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Hi,
I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Hi,
While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script.
*** Error: The following error was encountered on the output file.
Script.sh: 3043492 Segmentation fault(coredump)
Please let me know how to get through it.
... (5 Replies)
Dear all,
I used debugger from C++ and these are the message I got:
Program received signal SIGSEGV, Segmentation fault.
0x00323fc0 in free () from /lib/tls/libc.so.6
(gdb) info s
#0 0x00323fc0 in free () from /lib/tls/libc.so.6
#1 0x00794fa1 in operator delete () from... (5 Replies)
sometimes for this code i get a segmentation fault for codes llike this
:
int main{
int * a= 0;
int b;
a = (int*)malloc(sizeof(int));
///some code using these variable but no freeing of a
if(a){
free(a);
a = 0;
}
return... (3 Replies)
I am tring to install Lotus Domino/Notes 5.0.5 on a AIX 4.3.3 server.
I go to run the cdrom/ibmpow/install and I get the following error.
Lotus Notes for Unix Install Program
---------------------------------------------
./install: 10088 Segmentation fault
This had Lotus Notes installed... (1 Reply)
hi all
i'm trying to execute a c program under linux RH and it gives me segmentation fault, this program was running under unix at&t
anybody kow what the problem could be?
thanx in advance
regards (2 Replies)