Operating System - HP-UX
1752800 Members
5685 Online
108789 Solutions
New Discussion юеВ

How to generate a SIGSEGV in a program.

 
SOLVED
Go to solution
Shashibhushan Gokhale
Occasional Contributor

How to generate a SIGSEGV in a program.

Hello,

We are trying to debug an application in which SIGSEGV is generated.

We are trying to write a small test program to simulate the problem.

Hence, although it may sound funny :) I want my program to generate SIGSEGV.

I do not want ot use the raise(SIGSEGV) or kill -11 approach.

I have tried the following way:

char* abc = NULL
strcpy(abc,"TEST");

but instead of generating SIGSEGV(signal 11), it is generating SIGBUS(signal 10).

I am using aCC compiler on HP-UX11i OS.

Can anyone help me writing a piece of code that would generate a SIGSEGV?

Regards,
Shashibhushan Gokhale
7 REPLIES 7
Mark Grant
Honored Contributor

Re: How to generate a SIGSEGV in a program.

This does it for me, but on a linux box. You mileage may vary.

main(){
short b;
b+=1234;
printf("%sd",b);
}
Never preceed any demonstration with anything more predictive than "watch this"
Shashibhushan Gokhale
Occasional Contributor

Re: How to generate a SIGSEGV in a program.

Hi Mark,

As you guessed, it is not working in my case.
Anyway, thanks for the help.

Regards,
Shashibhushan
Mark Grant
Honored Contributor

Re: How to generate a SIGSEGV in a program.

does making the number assignment larger help? As in,
b+=12345

Never preceed any demonstration with anything more predictive than "watch this"
Elmar P. Kolkman
Honored Contributor
Solution

Re: How to generate a SIGSEGV in a program.

I got it with the following:
main(int argc,char **argv){
int i;
for (i=0;;i++)
argv[1]=argv[i];
}

Every problem has at least one solution. Only some solutions are harder to find.
Umapathy S
Honored Contributor

Re: How to generate a SIGSEGV in a program.

Shashi,
How about this


main()
{
int val[10];
val[9999999999]=100;
}

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Shashibhushan Gokhale
Occasional Contributor

Re: How to generate a SIGSEGV in a program.

The approach suggested by Elmar worked fine.
The approach suggested by Umapathy didn't compile and it gave a nasty compile time error.

Anyway thanks to all of you for your help.
Umapathy S
Honored Contributor

Re: How to generate a SIGSEGV in a program.

Shashi,
Very sorry. Didnt test it. Wrote it from top of my head. If you have decreased a couple of zeros then it would have done fine except that warning.

cheers
Umapathy
Arise Awake and Stop NOT till the goal is Reached!