]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
copyPasteCompatX11.c code generating unnecessary Coverity warning
authorOliver Kurth <okurth@vmware.com>
Mon, 17 Jun 2019 18:41:38 +0000 (11:41 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 17 Jun 2019 18:41:38 +0000 (11:41 -0700)
This patch aims to fix an issue found by Coverity Scan.

This issue is a False Positive, the outBuf is only freed in specific
scenario, so there is no 'BAD FREE'.  But it's better to reconstruct the
related code to clear the SCA error.

open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c

index 20b2cc0116c618eb4fca04c56303ebe6c63ebffe..e8eca5176d6194171c27d25125f4f4e611402015 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2005-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2005-2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -581,50 +581,41 @@ CopyPasteSelectionGetCB(GtkWidget        *widget,         // IN: unused
       return;
    }
 
-   /* If it is text copy paste, return gHostClipboardBuf. */
+   GdkAtom target;
 #ifndef GTK3
-   if (GDK_SELECTION_TYPE_STRING == selection_data->target ||
-       GDK_SELECTION_TYPE_UTF8_STRING == selection_data->target) {
+   target = selection_data->target;
 #else
-   if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) ||
-       GDK_SELECTION_TYPE_UTF8_STRING == gtk_selection_data_get_target(selection_data)) {
+   target = gtk_selection_data_get_target(selection_data);
 #endif
+
+   /* If it is text copy paste, return gHostClipboardBuf. */
+   if (GDK_SELECTION_TYPE_STRING == target ||
+       GDK_SELECTION_TYPE_UTF8_STRING == target) {
       char *outBuf = gHostClipboardBuf;
+      char *outStringBuf = NULL;
       size_t len = strlen(gHostClipboardBuf);
 
       /*
        * If target is GDK_SELECTION_TYPE_STRING, assume encoding is local code
        * set. Convert from utf8 to local one.
        */
-#ifndef GTK3
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target &&
-#else
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) &&
-#endif
+      if (GDK_SELECTION_TYPE_STRING == target &&
           !CodeSet_Utf8ToCurrent(gHostClipboardBuf,
                                  strlen(gHostClipboardBuf),
-                                 &outBuf,
+                                 &outStringBuf,
                                  &len)) {
          g_debug("CopyPasteSelectionGetCB: can not convert to current codeset\n");
          return;
       }
 
-#ifndef GTK3
-      gtk_selection_data_set(selection_data, selection_data->target, 8,
-#else
-      gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8,
-#endif
-                             outBuf, len);
-      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
-
-#ifndef GTK3
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target) {
-#else
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data)) {
-#endif
-         free(outBuf);
+      if (outStringBuf != NULL) {
+         outBuf = outStringBuf;
       }
 
+      gtk_selection_data_set(selection_data, target, 8, outBuf, len);
+      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
+
+      free(outStringBuf);
       return;
    }
 }