From 78fc18a82eb5a62d0e2366e330483f48f116ea35 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 5 Jan 2016 20:01:35 -0500 Subject: [PATCH] Added return value checking for readlink --- src/openalpr/support/platform.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/openalpr/support/platform.cpp b/src/openalpr/support/platform.cpp index a8db239..47d9569 100644 --- a/src/openalpr/support/platform.cpp +++ b/src/openalpr/support/platform.cpp @@ -32,19 +32,24 @@ namespace alpr char buffer[2048]; memset(buffer, 0, sizeof(buffer)); - readlink("/proc/self/exe", buffer, sizeof(buffer)); - - std::stringstream ss; - ss << buffer; - std::string exeFile = ss.str(); - std::string directory; - - const size_t last_slash_idx = exeFile.rfind('/'); - if (std::string::npos != last_slash_idx) + if (readlink("/proc/self/exe", buffer, sizeof(buffer)) > 0) { - directory = exeFile.substr(0, last_slash_idx); + std::stringstream ss; + ss << buffer; + std::string exeFile = ss.str(); + std::string directory; + + const size_t last_slash_idx = exeFile.rfind('/'); + if (std::string::npos != last_slash_idx) + { + directory = exeFile.substr(0, last_slash_idx); + } + return directory; + } + else + { + return "/"; } - return directory; #endif }