Andriamanitra / coctus

Command line tool for playing Clash of Code locally
MIT License
4 stars 2 forks source link

Segmentation errors not being backtraced. #47

Open daxida opened 3 months ago

daxida commented 3 months ago

Describe the bug If you get a SEGFAULT in C, the run command output message is inconsistent.

STDOUT and STDERR being UB is acceptable I guess, but it really should notify the SEGFAULT if it's possible.

Apparently it is also inconsistent in CG, so it may be hard to fix.

To Reproduce Write this C code in a tmp.c file at the root:

#include <stdio.h>

int main() {
    printf("Before SEGFAULT\n");
    fprintf(stderr, "STDERR Before SEGFAULT\n");

    // This doesn't SEGFAULT in CG but it does for me... weird
    // int seg[10];
    // seg[11] = -1;

    // This segfaults in CG but doesnt backtrace the faulty line
    // int seg[10];
    // seg[1000] = -1;

    int *ptr = NULL;
    *ptr = 10;

    printf("After SEGFAULT\n");
    fprintf(stderr, "STDERR After SEGFAULT\n");

    return 0;
}

Load any clash, then run the command: cargo run -- run --build-command "gcc -o tmp tmp.c" --command "./tmp"

Expected behavior image

What happens image