]> granicus.if.org Git - python/commitdiff
python-gdb.py: Replace invalid Unicode character with U+FFFD to be able to
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 11 Apr 2013 19:37:45 +0000 (21:37 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 11 Apr 2013 19:37:45 +0000 (21:37 +0200)
display invalid strings. Such strings can be found while Python is creating a
new string, in a text decoder for example, when Python is compiled in debug
mode.

Tools/gdb/libpython.py

index cab226e5d04b143173f9bdaa7c2a887141689bfa..20dcda8d12c6e73bbbe3d3b2044a8c4306f3b68b 100644 (file)
@@ -1160,7 +1160,9 @@ class PyUnicodeObjectPtr(PyObjectPtr):
         # Convert the int code points to unicode characters, and generate a
         # local unicode instance.
         # This splits surrogate pairs if sizeof(Py_UNICODE) is 2 here (in gdb).
-        result = u''.join([_unichr(ucs) for ucs in Py_UNICODEs])
+        result = u''.join([
+            (_unichr(ucs) if ucs <= 0x10ffff else '\ufffd')
+            for ucs in Py_UNICODEs])
         return result
 
     def write_repr(self, out, visited):