test.c

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>

void read_file ( FILE * file ) {
    size_t  len = 0;
    char *  line = NULL;
    ssize_t bytes_read;
    while ( ( bytes_read = getline ( &line, &len, file ) ) != -1 ) {
        printf ( "%s", line );
    }
    free ( line );
}
int main ( void ) {
    FILE *  file;
    file = fopen ( "/etc/fstab", "r" );
    read_file ( file );
    fclose ( file );
    return 0;
}

tcc -run test.c
# /etc/fstab: static file system information.
Segmentation fault

Then swap lines from:
size_t  len = 0;
char *  line = NULL;
to:
char *  line = NULL;
size_t  len = 0;

tcc -run test.c
# /etc/fstab: static file system information.
#
# noatime turns off ...

So this swap fixed the problem. It is real magick
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to