Menu

#1485 Viewer: pasting text adds extra null character (^@) at the end

None
open-accepted
nobody
None
5
2019-10-21
2019-09-18
nn ds
No

When copying text from the client host and pasting to the remote desktop, an extra null character is added. This may be obfuscated by certain applications or clipboard software. I was able to observe it only when pasting into emacs.

Reproduce:

  1. Copy <text> on windows client</text>
  2. Paste clipboard contents into emacs window on remote desktop
  3. Observe pasted value of '<text>^@', where '^@' is a single logical character identified by emacs as Ctrl-@ / 0x00 / null character.</text>

Possible Cause:
In AnsiStringStorage.cpp: void AnsiStringStorage::fromStringStorage, the following code is used to convert string formats.

  // WideCharToMultiByte returns result length including terminating null character 
  int symbolCount = WideCharToMultiByte(CP_ACP, 0, src->getString(), -1, 
                                        NULL, 0, NULL, NULL) + 1;

Both the comment in the code and the WideCharToMultiByte function documentation agree: the return result length includes the terminating null character. Adding an additional +1 to that length may be extraneous. Removing the extra +1 appears to resolve the issue.

Discussion

  • Anton

    Anton - 2019-10-08
    • status: open --> open-accepted
    • Group: -->
     
  • sapentidiot

    sapentidiot - 2019-10-21

    This seems to affect most java applications too, If pasted into jave it shows as if there is no extra character but there is one when selecting or moving between characters with arrow keys.

     

    Last edit: sapentidiot 2019-10-21

Log in to post a comment.

MongoDB Logo MongoDB