]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix Coverity reported issue in dndUIX11.cpp
authorOliver Kurth <okurth@vmware.com>
Wed, 30 Oct 2019 18:18:23 +0000 (11:18 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 30 Oct 2019 18:18:23 +0000 (11:18 -0700)
- 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 1a3b8d00a2574dadc8c3336e2ea303469ff3c782..70074384257c5f98b23a05b1281b05175b1a88fd 100644 (file)
@@ -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);
 }