We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CTRL-C in a textinput crashes the app
<!--
The issue tracker is a tool to address bugs.
Please use the #kivy IRC channel on freenode or Stack Overflow for
support questions, more information at https://git.io/vM1yQ.

Before opening a new issue, make sure you do the following:
    * check that your issue isn't already filed: https://git.io/vM1iE
    * prepare a short, runnable example that reproduces the issue
    * reproduce the problem with the latest development version of Kivy
    * double-check that the issue is indeed a bug and not a support request
-->

### Versions

* Python: 3.6.3
* OS: Windows 10
* Kivy: 1.10.0
* Kivy installation method: using pip, followed the steps shown in the guide

### Description

Trying to use CTRL-C to copy text from a textinput, and the program crashes.

### Code and Logs

```python
import kivy
from kivy.uix.textinput import TextInput
from kivy.app import App

class program(App):
    def build(self):
        return TextInput()

prog = program()
prog.run()


Traceback (most recent call last):
   File "E:/pycharm/MethasiaChatSurelyUnstable/vladegay.py", line 12, in <module>
     prog.run()
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\app.py", line 828, in run
     runTouchApp()
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop
     self._mainloop()
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 602, in _mainloop
     self.modifiers):
   File "kivy\_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:8146)
   File "kivy\_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy\_event.c:14035)
   File "kivy\_event.pyx", line 1149, in kivy._event.EventObservers._dispatch (kivy\_event.c:13564)
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\__init__.py", line 159, in _on_window_key_down
     return self.dispatch('on_key_down', keycode, text, modifiers)
   File "kivy\_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:8146)
   File "kivy\_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy\_event.c:14035)
   File "kivy\_event.pyx", line 1149, in kivy._event.EventObservers._dispatch (kivy\_event.c:13564)
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\textinput.py", line 2404, in keyboard_on_key_down
     self.copy()
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\textinput.py", line 1712, in copy
     return Clipboard.copy(self.selection_text)
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\clipboard\__init__.py", line 73, in copy
     self._copy(data)
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\clipboard\__init__.py", line 87, in _copy
     self.put(data, self._clip_mime_type)
   File "C:\Users\hellNo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\clipboard\clipboard_winctypes.py", line 55, in put
     msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))
 ValueError: embedded null character

```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kivy/core/clipboard/clipboard_winctypes.py`
Content:
```
1 '''
2 Clipboard windows: an implementation of the Clipboard using ctypes.
3 '''
4 
5 __all__ = ('ClipboardWindows', )
6 
7 from kivy.utils import platform
8 from kivy.core.clipboard import ClipboardBase
9 
10 if platform != 'win':
11     raise SystemError('unsupported platform for Windows clipboard')
12 
13 import ctypes
14 from ctypes import wintypes
15 user32 = ctypes.windll.user32
16 kernel32 = ctypes.windll.kernel32
17 msvcrt = ctypes.cdll.msvcrt
18 c_char_p = ctypes.c_char_p
19 c_wchar_p = ctypes.c_wchar_p
20 
21 
22 class ClipboardWindows(ClipboardBase):
23 
24     def get(self, mimetype='text/plain'):
25         GetClipboardData = user32.GetClipboardData
26         GetClipboardData.argtypes = [wintypes.UINT]
27         GetClipboardData.restype = wintypes.HANDLE
28 
29         user32.OpenClipboard(user32.GetActiveWindow())
30         # Standard Clipboard Format "1" is "CF_TEXT"
31         pcontents = GetClipboardData(13)
32 
33         # if someone pastes a FILE, the content is None for SCF 13
34         # and the clipboard is locked if not closed properly
35         if not pcontents:
36             user32.CloseClipboard()
37             return ''
38         data = c_wchar_p(pcontents).value.encode(self._encoding)
39         user32.CloseClipboard()
40         return data
41 
42     def put(self, text, mimetype='text/plain'):
43         text = text.decode(self._encoding)  # auto converted later
44         text += u'\x00'
45 
46         SetClipboardData = user32.SetClipboardData
47         SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]
48         SetClipboardData.restype = wintypes.HANDLE
49 
50         GlobalAlloc = kernel32.GlobalAlloc
51         GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]
52         GlobalAlloc.restype = wintypes.HGLOBAL
53 
54         CF_UNICODETEXT = 13
55 
56         user32.OpenClipboard(user32.GetActiveWindow())
57         user32.EmptyClipboard()
58         hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))
59         msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))
60         SetClipboardData(CF_UNICODETEXT, hCd)
61         user32.CloseClipboard()
62 
63     def get_types(self):
64         return ['text/plain']
65
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kivy/core/clipboard/clipboard_winctypes.py b/kivy/core/clipboard/clipboard_winctypes.py
--- a/kivy/core/clipboard/clipboard_winctypes.py
+++ b/kivy/core/clipboard/clipboard_winctypes.py
@@ -56,7 +56,9 @@
         user32.OpenClipboard(user32.GetActiveWindow())
         user32.EmptyClipboard()
         hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))
-        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))
+
+        # ignore null character for strSource pointer
+        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text[:-1]))
         SetClipboardData(CF_UNICODETEXT, hCd)
         user32.CloseClipboard()

{"golden_diff": "diff --git a/kivy/core/clipboard/clipboard_winctypes.py b/kivy/core/clipboard/clipboard_winctypes.py\n--- a/kivy/core/clipboard/clipboard_winctypes.py\n+++ b/kivy/core/clipboard/clipboard_winctypes.py\n@@ -56,7 +56,9 @@\n         user32.OpenClipboard(user32.GetActiveWindow())\n         user32.EmptyClipboard()\n         hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))\n-        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))\n+\n+        # ignore null character for strSource pointer\n+        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text[:-1]))\n         SetClipboardData(CF_UNICODETEXT, hCd)\n         user32.CloseClipboard()\n", "issue": "CTRL-C in a textinput crashes the app\n<!--\r\nThe issue tracker is a tool to address bugs.\r\nPlease use the #kivy IRC channel on freenode or Stack Overflow for\r\nsupport questions, more information at https://git.io/vM1yQ.\r\n\r\nBefore opening a new issue, make sure you do the following:\r\n    * check that your issue isn't already filed: https://git.io/vM1iE\r\n    * prepare a short, runnable example that reproduces the issue\r\n    * reproduce the problem with the latest development version of Kivy\r\n    * double-check that the issue is indeed a bug and not a support request\r\n-->\r\n\r\n### Versions\r\n\r\n* Python: 3.6.3\r\n* OS: Windows 10\r\n* Kivy: 1.10.0\r\n* Kivy installation method: using pip, followed the steps shown in the guide\r\n\r\n### Description\r\n\r\nTrying to use CTRL-C to copy text from a textinput, and the program crashes.\r\n\r\n### Code and Logs\r\n\r\n```python\r\nimport kivy\r\nfrom kivy.uix.textinput import TextInput\r\nfrom kivy.app import App\r\n\r\nclass program(App):\r\n    def build(self):\r\n        return TextInput()\r\n\r\nprog = program()\r\nprog.run()\r\n\r\n\r\nTraceback (most recent call last):\r\n   File \"E:/pycharm/MethasiaChatSurelyUnstable/vladegay.py\", line 12, in <module>\r\n     prog.run()\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\app.py\", line 828, in run\r\n     runTouchApp()\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\base.py\", line 504, in runTouchApp\r\n     EventLoop.window.mainloop()\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\window\\window_sdl2.py\", line 663, in mainloop\r\n     self._mainloop()\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\window\\window_sdl2.py\", line 602, in _mainloop\r\n     self.modifiers):\r\n   File \"kivy\\_event.pyx\", line 714, in kivy._event.EventDispatcher.dispatch (kivy\\_event.c:8146)\r\n   File \"kivy\\_event.pyx\", line 1225, in kivy._event.EventObservers.dispatch (kivy\\_event.c:14035)\r\n   File \"kivy\\_event.pyx\", line 1149, in kivy._event.EventObservers._dispatch (kivy\\_event.c:13564)\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\window\\__init__.py\", line 159, in _on_window_key_down\r\n     return self.dispatch('on_key_down', keycode, text, modifiers)\r\n   File \"kivy\\_event.pyx\", line 714, in kivy._event.EventDispatcher.dispatch (kivy\\_event.c:8146)\r\n   File \"kivy\\_event.pyx\", line 1225, in kivy._event.EventObservers.dispatch (kivy\\_event.c:14035)\r\n   File \"kivy\\_event.pyx\", line 1149, in kivy._event.EventObservers._dispatch (kivy\\_event.c:13564)\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\uix\\textinput.py\", line 2404, in keyboard_on_key_down\r\n     self.copy()\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\uix\\textinput.py\", line 1712, in copy\r\n     return Clipboard.copy(self.selection_text)\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\clipboard\\__init__.py\", line 73, in copy\r\n     self._copy(data)\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\clipboard\\__init__.py\", line 87, in _copy\r\n     self.put(data, self._clip_mime_type)\r\n   File \"C:\\Users\\hellNo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\kivy\\core\\clipboard\\clipboard_winctypes.py\", line 55, in put\r\n     msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))\r\n ValueError: embedded null character\r\n\r\n```\r\n\n", "before_files": [{"content": "'''\nClipboard windows: an implementation of the Clipboard using ctypes.\n'''\n\n__all__ = ('ClipboardWindows', )\n\nfrom kivy.utils import platform\nfrom kivy.core.clipboard import ClipboardBase\n\nif platform != 'win':\n    raise SystemError('unsupported platform for Windows clipboard')\n\nimport ctypes\nfrom ctypes import wintypes\nuser32 = ctypes.windll.user32\nkernel32 = ctypes.windll.kernel32\nmsvcrt = ctypes.cdll.msvcrt\nc_char_p = ctypes.c_char_p\nc_wchar_p = ctypes.c_wchar_p\n\n\nclass ClipboardWindows(ClipboardBase):\n\n    def get(self, mimetype='text/plain'):\n        GetClipboardData = user32.GetClipboardData\n        GetClipboardData.argtypes = [wintypes.UINT]\n        GetClipboardData.restype = wintypes.HANDLE\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        # Standard Clipboard Format \"1\" is \"CF_TEXT\"\n        pcontents = GetClipboardData(13)\n\n        # if someone pastes a FILE, the content is None for SCF 13\n        # and the clipboard is locked if not closed properly\n        if not pcontents:\n            user32.CloseClipboard()\n            return ''\n        data = c_wchar_p(pcontents).value.encode(self._encoding)\n        user32.CloseClipboard()\n        return data\n\n    def put(self, text, mimetype='text/plain'):\n        text = text.decode(self._encoding)  # auto converted later\n        text += u'\\x00'\n\n        SetClipboardData = user32.SetClipboardData\n        SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]\n        SetClipboardData.restype = wintypes.HANDLE\n\n        GlobalAlloc = kernel32.GlobalAlloc\n        GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]\n        GlobalAlloc.restype = wintypes.HGLOBAL\n\n        CF_UNICODETEXT = 13\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        user32.EmptyClipboard()\n        hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))\n        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))\n        SetClipboardData(CF_UNICODETEXT, hCd)\n        user32.CloseClipboard()\n\n    def get_types(self):\n        return ['text/plain']\n", "path": "kivy/core/clipboard/clipboard_winctypes.py"}], "after_files": [{"content": "'''\nClipboard windows: an implementation of the Clipboard using ctypes.\n'''\n\n__all__ = ('ClipboardWindows', )\n\nfrom kivy.utils import platform\nfrom kivy.core.clipboard import ClipboardBase\n\nif platform != 'win':\n    raise SystemError('unsupported platform for Windows clipboard')\n\nimport ctypes\nfrom ctypes import wintypes\nuser32 = ctypes.windll.user32\nkernel32 = ctypes.windll.kernel32\nmsvcrt = ctypes.cdll.msvcrt\nc_char_p = ctypes.c_char_p\nc_wchar_p = ctypes.c_wchar_p\n\n\nclass ClipboardWindows(ClipboardBase):\n\n    def get(self, mimetype='text/plain'):\n        GetClipboardData = user32.GetClipboardData\n        GetClipboardData.argtypes = [wintypes.UINT]\n        GetClipboardData.restype = wintypes.HANDLE\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        # Standard Clipboard Format \"1\" is \"CF_TEXT\"\n        pcontents = GetClipboardData(13)\n\n        # if someone pastes a FILE, the content is None for SCF 13\n        # and the clipboard is locked if not closed properly\n        if not pcontents:\n            user32.CloseClipboard()\n            return ''\n        data = c_wchar_p(pcontents).value.encode(self._encoding)\n        user32.CloseClipboard()\n        return data\n\n    def put(self, text, mimetype='text/plain'):\n        text = text.decode(self._encoding)  # auto converted later\n        text += u'\\x00'\n\n        SetClipboardData = user32.SetClipboardData\n        SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]\n        SetClipboardData.restype = wintypes.HANDLE\n\n        GlobalAlloc = kernel32.GlobalAlloc\n        GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]\n        GlobalAlloc.restype = wintypes.HGLOBAL\n\n        CF_UNICODETEXT = 13\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        user32.EmptyClipboard()\n        hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))\n\n        # ignore null character for strSource pointer\n        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text[:-1]))\n        SetClipboardData(CF_UNICODETEXT, hCd)\n        user32.CloseClipboard()\n\n    def get_types(self):\n        return ['text/plain']\n", "path": "kivy/core/clipboard/clipboard_winctypes.py"}]}