tinycc-devel
[Top][All Lists]
Advanced

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

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


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

This issue exists only in 0.9.25 version (http://download.savannah.nongnu.org/releases/tinycc/0.9.25.tar.bz2)
I've installed tcc from git (git://repo.or.cz/tinycc.git) and this bug dissapeared
Thanks!


2013/1/28 Андрей Аладьев <address@hidden>
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]