Mail Archives: djgpp/1997/11/09/03:47:18
Hi!
Nate Eldredge (was it in private letter?) wrote:
This example worked for me under both CWSDPMI r3 and Windows 3.1.
#include <stdio.h>
#include <signal.h>
void handler(int sig)
{
printf("Received signal %d\n",sig);
fflush(stdout);
/* clean up */
exit(1); /* or whatever else */
}
int main(void)
{
signal(SIGSEGV,handler);
/* Overflow the stack */
alloca(1000000);
/* Touch the stack to cause a fault */
printf("This isn't going to work");
return 0;
}
Running it prints "Received signal 291", which is evidently SIGSEGV.
Yes, the example works. And this one doesn't under the same circumstances
(dont optimize to preserve recursion!):
#include <stdio.h>
#include <signal.h>
void handler(int sig)
{
fprintf(stderr, "Received signal %d\n",sig);
fflush(stderr);
exit(1); /* or whatever else */
}
/* deeply recursive */
int myproc(int a, double t)
{
if (a<0) return 1;
else return myproc(a-1, a+0.23);
}
int main(void)
{
signal(SIGSEGV,handler);
/* Overflow the stack with recursive calls */
myproc(1000000, 23.4);
printf("No stack overflow.");
return 0;
}
--
-- * --
-- Roman A. Suzi * Petrozavodsk Karelia Russia --
-- http://sampo.karelia.ru/~rnd --
- Raw text -