tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] tinycc segfault with gnu getline for unknown reason


From: Андрей Аладьев
Subject: [Tinycc-devel] tinycc segfault with gnu getline for unknown reason
Date: Mon, 28 Jan 2013 19:35:35 +0300

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]