From 9a14300ec306dcec060a255ee39c5955a5de38c1 Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Fri, 25 May 2018 10:26:20 +0200 Subject: [PATCH] [Filesystem] Fixed errno issue found by Coverity system [Bug] Coverity issue 835432 Documentation of nftw() function says that the result can be -1, which is not valid error code for system_error constructor. To resolve such problem, the -1 value is translated to IOError code. [Verification] Code compiles without errors. TCT passrate of filesystem module is 100%. Change-Id: I92805294270b4969fd545a413c03c565fdef7afd Signed-off-by: Piotr Kosko --- src/filesystem/filesystem_utils.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/filesystem/filesystem_utils.cc b/src/filesystem/filesystem_utils.cc index 3ab4dd39..f56cab79 100644 --- a/src/filesystem/filesystem_utils.cc +++ b/src/filesystem/filesystem_utils.cc @@ -234,6 +234,11 @@ void RemoveDirectoryRecursively(const std::string& path) { 128, FTW_DEPTH | FTW_PHYS); if (res) { + if (-1 == res) { + // -1 can be returned by nftw() function, to prevent invalid translation of error in + // std::system_error constructor, such situation will be treated as generic IOError + res = EIO; + } throw std::system_error{res, std::generic_category(), "Failed to remove directory recursively: "s + std::strerror(res)}; } -- 2.34.1