# HG changeset patch # User Andrew Innes # Date 922402758 0 # Node ID a0423d2b9302d22bfc962bc8067985bbebb2a925 # Parent e422a11cf832175f128e5f96e1c9a8873cf13dae (Fw32_set_clipboard_data): Take into account line ends when calculating clipboard storage needed for non-ASCII text. diff -r e422a11cf832 -r a0423d2b9302 src/w32select.c --- a/src/w32select.c Thu Mar 25 22:56:34 1999 +0000 +++ b/src/w32select.c Thu Mar 25 22:59:18 1999 +0000 @@ -99,10 +99,10 @@ BOOL ok = TRUE; HANDLE htext; int nbytes; - int truelen; + int truelen, nlines = 0; unsigned char *src; unsigned char *dst; - + CHECK_STRING (string, 0); if (!NILP (frame)) @@ -112,6 +112,16 @@ nbytes = STRING_BYTES (XSTRING (string)) + 1; src = XSTRING (string)->data; + dst = src; + + /* We need to know how many lines there are, since we need CRLF line + termination for compatibility with other Windows Programs. + avoid using strchr because it recomputes the length every time */ + while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) + { + nlines++; + dst++; + } { /* Since we are now handling multilingual text, we must consider @@ -134,14 +144,7 @@ standard CF_TEXT clipboard format uses CRLF line endings, while Emacs uses just LF internally). */ - truelen = nbytes; - dst = src; - /* avoid using strchr because it recomputes the length everytime */ - while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) - { - truelen++; - dst++; - } + truelen = nbytes + nlines; if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) goto error; @@ -191,7 +194,7 @@ (Fcheck_coding_system (Vnext_selection_coding_system), &coding); Vnext_selection_coding_system = Qnil; coding.mode |= CODING_MODE_LAST_BLOCK; - bufsize = encoding_buffer_size (&coding, nbytes); + bufsize = encoding_buffer_size (&coding, nbytes) + nlines; if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL) goto error; if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)