Make file_id_for_fd return kInvalidFiledID when passed a negative fd

Rather than making fstat do this, make it explicit.
This commit is contained in:
ridiculousfish 2017-02-06 10:01:33 -08:00
parent 6eb1e31070
commit 83f386347f

View file

@ -683,7 +683,7 @@ file_id_t file_id_t::file_id_from_stat(const struct stat *buf) {
file_id_t file_id_for_fd(int fd) { file_id_t file_id_for_fd(int fd) {
file_id_t result = kInvalidFileID; file_id_t result = kInvalidFileID;
struct stat buf = {}; struct stat buf = {};
if (0 == fstat(fd, &buf)) { if (fd >= 0 && 0 == fstat(fd, &buf)) {
result = file_id_t::file_id_from_stat(&buf); result = file_id_t::file_id_from_stat(&buf);
} }
return result; return result;