From 83f386347f26336850e2efcd169d99e9ec89f027 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 6 Feb 2017 10:01:33 -0800 Subject: [PATCH] Make file_id_for_fd return kInvalidFiledID when passed a negative fd Rather than making fstat do this, make it explicit. --- src/wutil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index 10122453b..c989269cd 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -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 result = kInvalidFileID; struct stat buf = {}; - if (0 == fstat(fd, &buf)) { + if (fd >= 0 && 0 == fstat(fd, &buf)) { result = file_id_t::file_id_from_stat(&buf); } return result;