From d39417c165502b90ef91ad6a62c51350a9318cb6 Mon Sep 17 00:00:00 2001 From: Takanori Suzuki Date: Tue, 24 Jan 2017 18:57:09 +0900 Subject: [PATCH] For avoiding crash, exit with error message if no devices or non-root user --- main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 6c05b7e..59e2358 100644 --- a/main.cpp +++ b/main.cpp @@ -428,6 +428,14 @@ int main() } std::sort(smartList.begin(), smartList.end(), [](auto lhs, auto rhs){return lhs.deviceName < rhs.deviceName;}); + if (smartList.size() == 0) + { + endwin(); + std::cerr << "No S.M.A.R.T readable devices." << std::endl; + std::cerr << "If you are non-root user, please use sudo or become root." << std::endl; + return 1; + } + WINDOW * windowVersion; windowVersion = newwin(1, width, 0, 0); @@ -503,4 +511,3 @@ int main() } } } -