Skip to content

zstd --fileliste windows_edited_filelist_with_empty_last_line.txt; fgets() result code == NULL "to early" due to empty line ending, low priority #2480

@halifir

Description

@halifir

zstd 1.4.8

When I use a fileliste edited with an Windows Editor als ASCII with CR+LF line endings and a last empty line,
i get the error
zstd -f -2 --fileliste windows_edited_filelist_with_empty_last_line.txt
Error : util.c, 317 : fgets(buf, (int) len, file)

When debugging zstd I saw, that the readLineFromChar is called
due the fact, that there is still something in the file (not feof() reached).

But the fgets result for the last line is NULL - and errno == 0. And then, after this fgets with result == NULL feof will be true.

To avoid this problem with my filelist, i changed the CONTROL (fgets) to CONTROL ((fgets != NULL) && (errno == 0)) like this, and a had success:


util.c
static size_t readLineFromFile(char* buf, size_t len, FILE* file)
{
...
    CONTROL( (fgets(buf, (int) len, file) != NULL) || (errno == 0)  ); // <<< last fgets for empty line in windows edited fileliste file produces a NULL and errno==0 


static int
readLinesFromFile(void* dst, size_t dstCapacity,
            const char* inputFileName)
{

    **while ( !feof(inputFile) ) {**

It is just an idea, to change util.c to improve robustness of zstd.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions