]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix Coverity reported issue in dndUIX11.cpp
authorOliver Kurth <okurth@vmware.com>
Wed, 11 Dec 2019 18:19:09 +0000 (10:19 -0800)
committerOliver Kurth <okurth@vmware.com>
Wed, 11 Dec 2019 18:19:09 +0000 (10:19 -0800)
- unsigned_compare: This greater-than-or-equal-to-zero comparison of an
  unsigned value is always true. end >= 0UL.
 Function: GetLastDirName

open-vm-tools/services/plugins/dndcp/dndUIX11.cpp

index 015dd363193eca38c94df107ea09cc0938179b3d..5f403a82602d228147bb6b47346ad974658dd2a7 100644 (file)
@@ -1636,7 +1636,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.
@@ -1650,26 +1650,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);
 }