C. To segmentation fault or not to segmentation fault, that is the question.
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! This will NOT even compile on gcc 2.95.3 for the AMIGA, but WORKS correctly on OSX 10.14.1, gcc 4.2.1.
ALSO IMPORTANT! This compiles and WORKS perfectly on the AMIGA but gives a segmentation fault on OSX 10.14.1, gcc 4.2.1.
As you can see the second code gives a Segmentation fault: 11 on OSX 10.14.1, gcc 4.2.1 but compiles and works correctly on the AMIGA.
Can anyone explain why there is a SEGMENTATION FAULT when the if conditional statement is inside the 'main()' function to start with and the assignments set?
64 bit?
No, AMIGA A1200 is Motorola 68020 CPU 32 bit, newest gcc 2.95.3.
Yes, APPLE MBP is Intel 64 bit, newest gcc 4.2.1.
argc is _defined_ as an integer in the 'main()' function.
As for the stack quite possibly, but why? I am only comparing and argc integer against a fixed number.
Why should ANY assignments BEFORE the unrelated conditional statement crash out on this MBP?
There is little or nothing on the web about it?
And it compiles and works on the ancient gcc 2.95.3 for the equally ancient AMIGA A1200.
I understood correctly?
On a 64-bit system without parameters, the code gives "Segmentation fault".
Is there no " Segmentation fault" on the 32-bit system when started without parameters?
If my assumptions are correct, when creating a stack in the "main" function of the 64-bit system, a layer in the form of a red zone from the previous stack is filled with machine zeros and the parameters get no value, which leads to segmentation. And when creating a frame in the 32-bit system of this red zone is not! And the garbage from the old frame gets into the parameters and therefore there is no segmentation. But this is still not correct.
P.S. Thanks "Auto Save Recovery" accidentally closed the tab.
--- Post updated at 21:03 ---
I apologize this line should be read like this
Quote:
Is there no " Segmentation fault" on the 32-bit system when started without parameters?
There is no " Segmentation fault" on the 32-bit system when started without parameters
Last edited by nezabudka; 03-15-2019 at 02:54 PM..
The system is actually supposed to crash when you do this, rather than let you get away with mangling data outside of bounds, but some systems are better at catching it than others.
The code was written for a real stock A1200 with HDD, Motorola 68020 32 bit, no FPU nor MMU.
This is a screenshot of the FS-UAE AMIGA emulator for THIS 64 bit MBP, OSX 10.14.1, using 68040 with FPU and MMU, and much more than the stock 2MB RAM, compiling the 'error.c' code that is in the OP using the AMIGA's gcc 2.95.3.
As you can see it IS working!
EDIT:
@C688...
That makes sense but I didn't see it. However the OP's first code block will not compile in gcc 2.95.3 as it crashes out so I am stuck with an 'illegal' operation for my fav' OS.
This User Gave Thanks to wisecracker For This Post:
Working by sheer coincidence. Going beyond the end of the array means you can't predict what data you'll find there. To avoid out of bounds errors, stay in bounds.
Hi Guys,
I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error:
"Segmentation fault"
Can someone please help me resolve this?
Thanks alot (2 Replies)
this is a network programming code to run a rock paper scissors in a client and server.
I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault.
-the segmentation fault is fixed
Current problem -Also... (3 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)
i have this code
int already_there(char *client_names, char *username) {
int i;
for(i = 0; i<NUM; i++) {
printf("HERE\n");
if (strcmp(client_names, username)==0) return(1);
}
return(0);
}
and i get a segmentation fault, whats wrong here? (7 Replies)
I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek:
#include </usr/include/mysql++/mysql++.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string.h>
using namespace std;
int outputToImport(const char*... (1 Reply)
If I do this.
Assume
struct life
{
char *nolife;
}
struct life **life;
// malloc initialization & everything
if(life->nolife == 0)
Would I get error at life->nolife if it is equal to 0.
wrong accession? (3 Replies)
Hi,
on a linux Red HAT(with Oracle DB 9.2.0.7) I have following error :
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
using channel ORA_DISK_1
Segmentation fault
What does it mean ? And the solution ?
Many thanks. (0 Replies)
Hi ,
During execution a backup binary i get following error
"Program error 11 (Segmentation fault), saving core file in '/usr/datatools"
Riyaz (2 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)