DaanDeMeyer / reproc

A cross-platform (C99/C++11) process library
MIT License
552 stars 65 forks source link

Bug in reproc_read()? #63

Closed supersv closed 3 years ago

supersv commented 3 years ago

Hi Daan,

First of all, I'd like to thank you for making and maintaining reproc.

I'm just starting out with the library, and while learning it I've noticed a strange line inside reproc_read():

return r == 0 ? -REPROC_EWOULDBLOCK : r;

It is understood that reproc_read() returns the number of bytes read upon success, and a negative value on failure. However, upon encountering a "would block" situation, it seems the result would be positive instead of negative, e.g. -(-EWOULDBLOCK)) on POSIX, and the caller won't be able to detect this error.

Am I missing something? Thanks.

DaanDeMeyer commented 3 years ago

Thanks for the report! This does indeed look like a bug. Pushed a commit to fix it.