This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

setjmp/longjmp & signal handlers bug


$ uname -a
CYGWIN_NT-5.1 fordpc 1.5.12(0.116/4/2) 2004-10-11 16:50 i686 unknown
unknown Cygwin

$ cat longjmp_signal.c
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

static jmp_buf env;

void
handler(int sig)
{
    longjmp(env, 1);
    puts("longjmp failed");
    exit(-2);
}

int
main(void)
{
    int i;

    for (i = 0; i < 2; i++)
    {
        volatile char *p = NULL;

        signal(SIGSEGV, handler);

        if (setjmp(env) == 0)
        {
            *p;
            puts("SEGV failed");
            exit(-1);
        }
        else
            printf("Partial success: %d\n", i);
    }

    puts("PASS");

    return 0;
}

$ gcc -g -O2 longjmp_signal.c -o longjmp_signal.exe

$ ./longjmp_signal.exe
Partial success: 0

$ echo $?
5

I would expect additional output:
Partial success: 1
PASS

and a 0 return status?

Thanks.

-- 
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained pilot...

Attachment: cygcheck.out
Description: Text document

Attachment: longjmp_signal.c
Description: Text document

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]