[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

[MD:1815]Bug of kill-ring action with NULL byte in string.



Shun-ichi GOTO <gotoh@xxxxxxxxxxx> writes:

> (無理が生じない範囲で)取り扱えるようにする事を希望します。

結局clipboard formatのバージョンを上げました。^^;;;
この結果、古いMeadowと、この変更後のversionのMeadowとの間には、
多言語テキストの通信は出来なくなりました。

from himi

formatは全然architecture/system独立性を持っていないので、
remote透過性のことを考えるとまずいですねぇ。
### やっぱ、OLEにしたほうがいいんかなぁ。

2000-06-15  MIYASHITA Hisashi  <himi@xxxxxxxxxxxxxxxxxxxxxxxxx>

	* mw32clpbd.c (W32_MULE_CB_REQSIZE):
	(W32_MULE_CB_SIZE):
	(W32_MULE_CB_CONTENTS):
	(W32_MULE_SET_CB):
	New macros to access new clipboard format.
	(Fw32_set_clipboard_data):
	(Fw32_get_clipboard_data):
	Use the above macros to set mule specific clipboard format.

	* w32.h (MULE_CLIPBOARD_FORMAT): modified in order to upgrade
	format version.

=== cd m:/cvswork/local/Meadow/src/
=== cvs -d :local:g:/repdev diff -u w32.h

Index: w32.h
===================================================================
RCS file: g:/repdev/Meadow/src/w32.h,v
retrieving revision 1.2
diff -u -r1.2 w32.h
--- w32.h	1999/02/17 16:22:29	1.2
+++ w32.h	2000/06/14 16:09:38
@@ -120,7 +120,12 @@
 /* W32 clipboard format for MULE text. */
 extern UINT w32_mule_clipboard_format;
 
-#define MULE_CLIPBOARD_FORMAT "Mule_TEXT"
+/* The old version of Meadow registers "Mule_TEXT" as emacs-mule
+   clipboard format, which is only emacs-mule text.  "Mule_TEXT_V2" is
+   a simple format to store size of emacs-mule text.  Its header is a
+   interger that specifies size of emacs-mule text, and the rest is
+   the text itself.  */
+#define MULE_CLIPBOARD_FORMAT "Mule_TEXT_V2"
 
 extern void init_ntproc ();
 extern void term_ntproc ();

=== cd m:/cvswork/local/Meadow/src/
=== cvs -d :local:g:/repdev diff -u mw32clpbd.c

Index: mw32clpbd.c
===================================================================
RCS file: g:/repdev/Meadow/src/mw32clpbd.c,v
retrieving revision 1.2
diff -u -r1.2 mw32clpbd.c
--- mw32clpbd.c	1999/02/17 16:22:14	1.2
+++ mw32clpbd.c	2000/06/14 16:14:22
@@ -32,6 +32,17 @@
 
 #define WRITE_BUF_SIZE 1024
 
+/* As to these definitions, we put no special meanings to size and
+   textlen.  You must take consideration null terminator or anything
+   else by yourself. */
+#define W32_MULE_CB_REQSIZE(textlen) ((textlen) + sizeof(int))
+#define W32_MULE_CB_SIZE(ptr) (*((int*)(ptr)))
+#define W32_MULE_CB_CONTENTS(ptr) ((ptr) + sizeof(int))
+#define W32_MULE_SET_CB(ptr, text, size)	\
+do {						\
+  memcpy (((ptr) + sizeof(int)), text, size);	\
+  (*((int*)(ptr))) = size;			\
+}while(0)
 
 Lisp_Object Vw32_clipboard_coding_system;
 int w32_mule_clipboard_format;
@@ -50,7 +61,7 @@
   HANDLE htext, hmuletext;
   struct coding_system coding;
   int htextsize, size;
-  unsigned char *lptext, *lpmuletext;
+  unsigned char *lptext, *lpmulecb;
   
 
   CHECK_STRING (string, 0);
@@ -67,13 +78,17 @@
     goto error;
   if (w32_mule_clipboard_format)
     {
-      if ((hmuletext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
-				    STRING_BYTES(XSTRING (string)) + 1)) == NULL)
+      if ((hmuletext =
+	   GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
+			W32_MULE_CB_REQSIZE (STRING_BYTES (XSTRING (string))
+					     + 1)))
+	  == NULL)
 	goto error;
-      if ((lpmuletext = (unsigned char *) GlobalLock (hmuletext)) == NULL)
+      if ((lpmulecb = (unsigned char *) GlobalLock (hmuletext)) == NULL)
 	goto error;
 
-      strcpy (lpmuletext, XSTRING (string)->data);
+      W32_MULE_SET_CB (lpmulecb, XSTRING (string)->data,
+		       STRING_BYTES(XSTRING (string)) + 1);
       GlobalUnlock (hmuletext);
     }
   if ((lptext = (unsigned char *) GlobalLock (htext)) == NULL)
@@ -139,7 +154,9 @@
     {
       if ((lptext = (unsigned char *) GlobalLock (hmuletext)) == NULL)
 	goto closeclip;
-      ret = build_string (lptext);
+      /* Subtract 1 for the NULL terminator.  */
+      ret = make_string (W32_MULE_CB_CONTENTS (lptext),
+			 W32_MULE_CB_SIZE (lptext) - 1);
       GlobalUnlock (hmuletext);
       goto closeclip;
     }