[Vm-dev] [commit] r2152 - Add Eliot's clipboard handling fix.

commits at squeakvm.org commits at squeakvm.org
Wed Mar 10 19:22:46 UTC 2010


Author: andreas
Date: 2010-03-10 11:22:45 -0800 (Wed, 10 Mar 2010)
New Revision: 2152

Modified:
   trunk/platforms/win32/vm/sqWin32Window.c
Log:
Add Eliot's clipboard handling fix.

Modified: trunk/platforms/win32/vm/sqWin32Window.c
===================================================================
--- trunk/platforms/win32/vm/sqWin32Window.c	2010-02-24 13:25:07 UTC (rev 2151)
+++ trunk/platforms/win32/vm/sqWin32Window.c	2010-03-10 19:22:45 UTC (rev 2152)
@@ -2353,7 +2353,6 @@
 int clipboardSize(void) { 
   HANDLE h;
   WCHAR *src;
-  unsigned char *tmp;
   int i, count, bytesNeeded;
 
   /* Do we have text in the clipboard? */
@@ -2370,18 +2369,20 @@
   /* How many bytes do we need to store those unicode chars in UTF8 format? */
   bytesNeeded = WideCharToMultiByte(CP_UTF8, 0, src, -1,
 				    NULL, 0, NULL, NULL );
-  tmp = malloc(bytesNeeded+1);
+  if (bytesNeeded > 0) {
+    unsigned char *tmp = malloc(bytesNeeded+1);
 
-  /* Convert Unicode text to UTF8. */
-  WideCharToMultiByte(CP_UTF8, 0, src, -1, tmp, bytesNeeded , NULL, NULL);
+    /* Convert Unicode text to UTF8. */
+    WideCharToMultiByte(CP_UTF8, 0, src, -1, tmp, bytesNeeded , NULL, NULL);
 
-  /* Count CrLfs for which we remove the extra Lf */
-  count = bytesNeeded; /* ex. terminating zero */
-  for(i=0; i<count; i++) {
-    if((tmp[i] == 13) && (tmp[i+1] == 10)) bytesNeeded--;
+    /* Count CrLfs for which we remove the extra Lf */
+    count = bytesNeeded; /* ex. terminating zero */
+    for(i=0; i<count; i++) {
+      if((tmp[i] == 13) && (tmp[i+1] == 10)) bytesNeeded--;
+    }
+    bytesNeeded--; /* discount terminating zero */
+    free(tmp); /* no longer needed */
   }
-  bytesNeeded--; /* discount terminating zero */
-  free(tmp); /* no longer needed */
 
   GlobalUnlock(h);
   CloseClipboard();



More information about the Vm-dev mailing list