# Buggy code
def read_clipboard(**kwargs):  # pragma: no cover
    """
    Read text from clipboard and pass to read_table. See read_table for the
    full argument list

    If unspecified, `sep` defaults to '\s+'

    Returns
    -------
    parsed : DataFrame
    """
    from pandas.util.clipboard import clipboard_get
    from pandas.io.parsers import read_table

    text = clipboard_get()

    # try to decode (if needed on PY3)
    # Strange. linux py33 doesn't complain, win py33 does
    if compat.PY3:
        try:
            text = compat.bytes_to_str(
                text,
                encoding=(kwargs.get("encoding") or get_option("display.encoding")),
            )
        except:
            pass

    # Excel copies into clipboard with \t seperation
    # inspect no more then the 10 first lines, if they
    # all contain an equal number (>0) of tabs, infer
    # that this came from excel and set 'sep' accordingly
    lines = text[:10000].split("\n")[:-1][:10]

    # Need to remove leading white space, since read_table
    # accepts:
    #    a  b
    # 0  1  2
    # 1  3  4

    counts = set([x.lstrip().count("\t") for x in lines])
    if len(lines) > 1 and len(counts) == 1 and counts.pop() != 0:
        kwargs["sep"] = "\t"

    if kwargs.get("sep") is None and kwargs.get("delim_whitespace") is None:
        kwargs["sep"] = "\s+"

    return read_table(StringIO(text), **kwargs)


# Traceback (OSError)
# Your code here
In [1]: df = pd.DataFrame(np.random.randn(10, 2))

In [2]: df.to_clipboard()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-1f8b11f0ff98> in <module>()
----> 1 df.to_clipboard()

c:\users\chris\documents\python-dev\pandas\pandas\core\generic.py in to_clipboard(self, excel, sep, **kwargs)
1236         """
1237         from pandas.io import clipboard
-> 1238         clipboard.to_clipboard(self, excel=excel, sep=sep, **kwargs)
1239
1240     def to_xarray(self):

c:\users\chris\documents\python-dev\pandas\pandas\io\clipboard.py in to_clipboard(obj, excel, sep, **kwargs)
96     else:
97         objstr = str(obj)
---> 98     clipboard_set(objstr)

c:\users\chris\documents\python-dev\pandas\pandas\util\clipboard.py in _copyWindows(text)
83                                  len(text.encode('utf-16-le')) + 2)
84     pchData = d.kernel32.GlobalLock(hCd)
---> 85     ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
86     d.kernel32.GlobalUnlock(hCd)
87     d.user32.SetClipboardData(CF_UNICODETEXT, hCd)

OSError: exception: access violation writing 0x0000000000000000

In [4]: pd.read_clipboard()
<segfault>

# Fixed code
def read_clipboard(**kwargs):  # pragma: no cover
    """
    Read text from clipboard and pass to read_table. See read_table for the
    full argument list

    If unspecified, `sep` defaults to '\s+'

    Returns
    -------
    parsed : DataFrame
    """
    encoding = kwargs.pop("encoding", "utf-8")

    # only utf-8 is valid for passed value because that's what clipboard
    # supports
    if encoding is not None and encoding.lower().replace("-", "") != "utf8":
        raise NotImplementedError("reading from clipboard only supports utf-8 encoding")

    from pandas.util.clipboard import clipboard_get
    from pandas.io.parsers import read_table

    text = clipboard_get()

    # try to decode (if needed on PY3)
    # Strange. linux py33 doesn't complain, win py33 does
    if compat.PY3:
        try:
            text = compat.bytes_to_str(
                text,
                encoding=(kwargs.get("encoding") or get_option("display.encoding")),
            )
        except:
            pass

    # Excel copies into clipboard with \t seperation
    # inspect no more then the 10 first lines, if they
    # all contain an equal number (>0) of tabs, infer
    # that this came from excel and set 'sep' accordingly
    lines = text[:10000].split("\n")[:-1][:10]

    # Need to remove leading white space, since read_table
    # accepts:
    #    a  b
    # 0  1  2
    # 1  3  4

    counts = set([x.lstrip().count("\t") for x in lines])
    if len(lines) > 1 and len(counts) == 1 and counts.pop() != 0:
        kwargs["sep"] = "\t"

    if kwargs.get("sep") is None and kwargs.get("delim_whitespace") is None:
        kwargs["sep"] = "\s+"

    return read_table(StringIO(text), **kwargs)