]> sourceware.org Git - cygwin-apps/cygutils.git/commitdiff
Fix getclip segfault on xterm selections
authorMark Geisert <mark@maxrnd.com>
Sun, 21 Nov 2021 10:15:07 +0000 (02:15 -0800)
committerMark Geisert <mark@maxrnd.com>
Sun, 21 Nov 2021 10:15:07 +0000 (02:15 -0800)
src/clip/getclip.c

index 5cdb8f1d4156b39beac743b6c937574a7d76fc40..4dbaa9786683cc43438974fa806c32dccf7a9c99 100644 (file)
@@ -399,6 +399,9 @@ getclip (FILE * out, flags_struct flags, FILE * f, char *name)
           return (0);
         }
 
+#if DEBUGGING
+      fprintf (stderr, "Using format: %u\n", format);
+#endif
       hglb = GetClipboardData (format);
 
       if (format == cygnativeformat)
@@ -476,9 +479,37 @@ getclip (FILE * out, flags_struct flags, FILE * f, char *name)
       char *prev;
       char *curr;
       char *pos;
+      UINT format;
 
       OpenClipboard (0);
+#if DEBUGGING
+      {
+        fprintf (stderr, "ThreadLocale: %u\nClipboardFormats:",
+                 GetThreadLocale ());
+        format = 0;
+        do {
+          format = EnumClipboardFormats (format);
+          fprintf (stderr, " %u", format);
+          if (format == CF_LOCALE)
+            fprintf (stderr, "(%u)", *(LCID *) GetClipboardData (CF_LOCALE));
+        } while (format != 0);
+        fprintf (stderr, "\n");
+      }
+#endif
+#if DEBUGGING
+      fprintf (stderr, "Using format: %u\n", CF_TEXT);
+#endif
       hglb = GetClipboardData (CF_TEXT); //TODO support CF_UNICODETEXT too?
+      if (!hglb)
+        {
+          DWORD err = GetLastError ();
+#if DEBUGGING
+          /* look up error code displayed here in w32api/winerror.h */
+          fprintf (stderr, "GetClipboardData returns %ld\n", err);
+#endif
+          CloseClipboard ();
+          return err != 0;
+        }
       lpstr = GlobalLock (hglb);
       lplen = strlen (lpstr);
 
@@ -532,9 +563,37 @@ getclip (FILE * out, flags_struct flags, FILE * f, char *name)
       char *prev;
       char *curr;
       char *pos;
+      UINT format;
 
       OpenClipboard (0);
+#if DEBUGGING
+      {
+        fprintf (stderr, "ThreadLocale: %u\nClipboardFormats:",
+                 GetThreadLocale ());
+        format = 0;
+        do {
+          format = EnumClipboardFormats (format);
+          fprintf (stderr, " %u", format);
+          if (format == CF_LOCALE)
+            fprintf (stderr, "(%u)", *(LCID *) GetClipboardData (CF_LOCALE));
+        } while (format != 0);
+        fprintf (stderr, "\n");
+      }
+#endif
+#if DEBUGGING
+      fprintf (stderr, "Using format: %u\n", CF_TEXT);
+#endif
       hglb = GetClipboardData (CF_TEXT); //TODO support CF_UNICODETEXT too?
+      if (!hglb)
+        {
+          DWORD err = GetLastError ();
+#if DEBUGGING
+          /* look up error code displayed here in w32api/winerror.h */
+          fprintf (stderr, "GetClipboardData returns %ld\n", err);
+#endif
+          CloseClipboard ();
+          return err != 0;
+        }
       lpstr = GlobalLock (hglb);
       lplen = strlen (lpstr);
 
This page took 0.0264 seconds and 5 git commands to generate.