]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[open-vm-tools Coverity] Fix Coverity scan reported issues in copyPasteUIX11.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)
- Non-static class member mHGGetListTime is not initialized in this constructor
 solution: add it into init list of constructor

- 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/copyPasteUIX11.cpp

index fad000e3a85115697ce94dab5721d000eba62c15..387cbc5ca357579653950ac47e18923a6b20aff7 100644 (file)
@@ -130,6 +130,7 @@ CopyPasteUIX11::CopyPasteUIX11()
    mPrimTime(0),
    mLastTimestamp(0),
    mThread(0),
+   mHGGetListTime(0),
    mHGGetFileStatus(DND_FILE_TRANSFER_NOT_STARTED),
    mBlockAdded(false),
    mBlockCtrl(0),
@@ -1090,26 +1091,11 @@ CopyPasteUIX11::LocalGetSelectionFileList(const Gtk::SelectionData& sd)      //
 utf::string
 CopyPasteUIX11::GetLastDirName(const utf::string &str)     // IN
 {
-   utf::string ret;
-   size_t start;
-   size_t end;
-
-   end = str.bytes() - 1;
-   if (end >= 0 && DIRSEPC == str[end]) {
-      end--;
-   }
-
-   if (end <= 0 || str[0] != DIRSEPC) {
-      return "";
-   }
-
-   start = end;
-
-   while (str[start] != DIRSEPC) {
-      start--;
-   }
-
-   return str.substr(start + 1, end - start);
+   char *baseName;
+   File_GetPathName(str.c_str(), NULL, &baseName);
+   utf::string s(baseName);
+   free(baseName);
+   return s;
 }