public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [cygutils - Chuck Wilson's collection of Cygwin utilities] branch master, updated. v1_4_16-11-g3e94e05
@ 2021-11-21 10:16 Mark Geisert
  0 siblings, 0 replies; only message in thread
From: Mark Geisert @ 2021-11-21 10:16 UTC (permalink / raw)
  To: cygwin-apps-cvs




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);
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-21 10:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-21 10:16 [cygutils - Chuck Wilson's collection of Cygwin utilities] branch master, updated. v1_4_16-11-g3e94e05 Mark Geisert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).