Skip to content

Reading from a pipe is messed up #14

@matthijskooijman

Description

@matthijskooijman

I tried reading output from stderr from a process, and it gets all messed up. It seems the length of the buffer returned is correct, but only the first couple of hundred bytes are filled, the rest are zeroes.

Looking at the code, it seems that read_atmost_n does not handle partial reads correctly. Changing this line to the following seems to fix this.

int read_bytes = read(fd, buf + rbytes, read_upto - rbytes)

On a related note, I suspect that if read_all resizes the buffer and causes a realloc, then the buffer variable might become invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions