[cygutils - Chuck Wilson's collection of Cygwin utilities] branch master, updated. v1_4_16-11-g3e94e05

Mark Geisert mgeisert@sourceware.org
Sun Nov 21 10:16:33 GMT 2021




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/cygutils.git;h=3e94e050af7ad4ac84d12c18e9408e4c4f34cb56

commit 3e94e050af7ad4ac84d12c18e9408e4c4f34cb56
Author: Mark Geisert <mark@maxrnd.com>
Date:   Sun Nov 21 02:15:07 2021 -0800

    Fix getclip segfault on xterm selections


Diff:
---
 src/clip/getclip.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/src/clip/getclip.c b/src/clip/getclip.c
index 5cdb8f1..4dbaa97 100644
--- a/src/clip/getclip.c
+++ b/src/clip/getclip.c
@@ -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);
 



More information about the Cygwin-apps-cvs mailing list