Why do I get a SIGSEGV?

Why are my programs getting runtime error (SIGSEV) during submissions but run well in all IDEs I’ve tried?
I’m pretty sure it’s not a case of out-of-range array access. What are the other possible faults?

1 Like

please check this this code works fine on codechef ide ,ideone.com but every time when i am submitting i am getting runtime error SIGSEGV CodeChef: Practical coding for everyone

  1. I do not quite understand why there are so many people have posted their own questions as answers for this question. Probably, this isn’t well moderated or there is something that I do not understand.
  2. Since, there is no code provided in the question the reason for getting SIGSEGV could not be determined. I am surprised that this old thread has 61 answers when actually there is no relevant information.

Refer Code Chef Wiki about status codes

why m getting SIGSEGV RUNTIME ERROR for problem LCOLLIS Problem - CodeChef solution is CodeChef: Practical coding for everyone

SIGSEV error pops up due to a segmentation fault

Possible reasons for segmentation fault are :

  • One of the array indices you used would’ve been an invalid index . This means that at some point of execution , your program uses a value for the array index that is either more than the size of the array or less than 0
  • When you try to dereference a pointer with NULL value
  • When you declare an array of a very huge size . In this case the compiler itself can’t handle the array . Hence it pops out segmentation fault

Try adhering to all of the specifications as mentioned by the admin

Also , this link may help you

getting SIGSEV onthis piece of code which is from the beginner fctrl problem

#include
using namespace std;
int main()
{
int num,n=1,zeroes=0,power=5;
cin>>num;
int i,j,k,arr[1000],res[1000];
for(i=0;i<num;i++)
{
cin>>arr[i];
}
for(j=0;j<num;j++)
{
zeroes=0;
power=5;
while((arr[j]/power)>0)
{
zeroes+=(arr[j]/power);
n++;
power*=5;
}
res[j]=zeroes;
}
for(k=0;k<num;k++)
cout<<res[k]<<endl;
return 0;
}

please help tried to write a very precise piece of code but it seems not to be working help;

why do i get SIGSEVAG for this code ?
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int m,n,i,indices,count=0;
cin>>n>>m;
int a[n]={0};
while(m–){
cin>>indices;
a[indices-1]=1;
}

	  for(i=0;i<n;i++){
	  	if(a[i]!=1){
		  
	  	count++;
	  	if(count%2==0&&count!=0)
	  	a[i]=3;
	  	if(count%2==1)
	  	a[i]=4;		     
	  }
}
	  
	for(i=0;i<n;i++){
		if(a[i]==4)
		cout<<i+1<<" ";

}
cout<<endl;
for(i=0;i<n;i++){

		if(a[i]==3)
		cout<<i+1<<" ";
	}
	cout<<endl;
}
return 0;

}

@vineeta1995
.Condition if(t[I]℅k==0)
Will give run time error if value of k=0;

@ankittt_jain you have declared array a[n]
If the value of n goes above 10^6 then you will get run time error.

please help why do i get SIGSEVG for this code
https://www.codechef.com/viewsolution/10818136

You can check here for all errors that mostly occurs at codechef https://www.codechef.com/wiki/status-codes

SIGSEGV : A SIGSEGV is an error(signal) caused by an invalid memory reference or a segmentation fault. You are probably trying to access an array element out of bounds or trying to use too much memory. Some of the other causes of a segmentation fault are : Using uninitialized pointers, dereference of NULL pointers, accessing memory that the program doesn’t own

@gokul95
“solution is CodeChef: Practical coding for everyone

You are getting SIGSEGV becuase you have take character pointer char* a and inputting directly into “a” by using scanf(“%s”,a); This is wrong. “a” is a pointer and has no memory alocated to it. You should first allocate memory to the pointer using malloc before taking inout.
a=(char* )malloc(sizeof(char)*SIZE)
where SIZE is the maximum input lenght of string + 1(1 extra for ‘\0’).
Just add this line before your scanf line.

I have tried many things and this code runs fine on my computer but on submitting I repeatedly get SIGSSEVG ?? You can check here.CodeChef: Practical coding for everyone

why do i get sigsevg for this code
https://www.codechef.com/viewsolution/11028794

why do i get sigsevg for the code : CodeChef: Practical coding for everyone

Go to Help—> FAQ
You get most of your answer there.

This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an array element out of bounds, or using too much memory.

Some things for you to try:

Make sure you aren’t using variables that haven’t been initialised. These may be set to 0 on your computer, but aren’t guaranteed to be on the judge.

Check every single occurrence of accessing an array element and see if it could possibly be out of bounds.

Make sure you aren’t declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work.

Make sure you aren’t declaring too much stack memory. Any large arrays should be declared globally, outside of any functions - putting an array of 100000 ints inside a function probably won’t work.

As [wikipedia][1] says

“It is an fault raised by hardware informing your operating system about memory access violation , for which os kernel in return generate a signal to the offending process , called SIGSEGV (or Core dumped).”

But in simple terms

"These errors are generated if any pointer(like in C language that provide low level memory access) is trying to access a memory location which has not been allocated to the program , or your program is trying to use memory which are not for the program "
[1]: Segmentation fault - Wikipedia

getting runtime SIGSEVG on this, don’t know why

https://www.codechef.com/viewsolution/11194997

why am i getting SIGSEV for this solution?

CodeChef: Practical coding for everyone.

what can i really do in order to remove it?