From: Oliver Kurth Date: Wed, 30 Oct 2019 18:18:23 +0000 (-0700) Subject: Fix Coverity reported issue in dndUIX11.cpp X-Git-Tag: stable-11.1.0~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72dd83874a5787b7ee431ea30e1c58dff0f56ae9;p=thirdparty%2Fopen-vm-tools.git Fix Coverity reported issue in dndUIX11.cpp - unsigned_compare: This greater-than-or-equal-to-zero comparison of an unsigned value is always true. end >= 0UL. Function: GetLastDirName --- diff --git a/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp b/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp index 1a3b8d00a..700743842 100644 --- a/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp +++ b/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp @@ -1639,7 +1639,7 @@ DnDUIX11::RequestData( * name, intended to isolate an individual DND operation's staging directory * name. * - * E.g. /tmp/VMwareDnD/abcd137/foo → abcd137 + * E.g. /tmp/VMwareDnD/abcd137 → abcd137 * * Results: * Returns session directory name on success, empty string otherwise. @@ -1653,26 +1653,15 @@ DnDUIX11::RequestData( std::string DnDUIX11::GetLastDirName(const std::string &str) { - std::string ret; - size_t start; - size_t end; - - end = str.size() - 1; - if (end >= 0 && DIRSEPC == str[end]) { - end--; - } - - if (end <= 0 || str[0] != DIRSEPC) { - return ""; - } - - start = end; - - while (str[start] != DIRSEPC) { - start--; + char *baseName; + File_GetPathName(str.c_str(), NULL, &baseName); + if (baseName) { + std::string s(baseName); + free(baseName); + return s; + } else { + return std::string(); } - - return str.substr(start + 1, end - start); }