summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-10-03 12:18:09 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-10-03 12:18:09 (GMT)
commitb86f08f743095c27641754fbfa941c38cdb381ef (patch)
treefbaba91a4fa306b875ac77fb3dec71c70e9c85ca
parent392f4139b32f99f8f1dbe72e4ed10c2fe8e4d09b (diff)
downloadcpython-b86f08f743095c27641754fbfa941c38cdb381ef.zip
cpython-b86f08f743095c27641754fbfa941c38cdb381ef.tar.gz
cpython-b86f08f743095c27641754fbfa941c38cdb381ef.tar.bz2
faulthandler: enhance dump_ascii() to escape also non-printable ASCII
characters (U+0000..U+001f and U+007f).
-rw-r--r--Python/traceback.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 565094b..5d60dad 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -541,15 +541,16 @@ dump_ascii(int fd, PyObject *text)
ch = PyUnicode_READ(kind, data, i);
else
ch = wstr[i];
- if (ch < 128) {
+ if (' ' <= ch && ch <= 126) {
+ /* printable ASCII character */
char c = (char)ch;
write(fd, &c, 1);
}
- else if (ch < 0xff) {
+ else if (ch <= 0xff) {
PUTS(fd, "\\x");
dump_hexadecimal(fd, ch, 2);
}
- else if (ch < 0xffff) {
+ else if (ch <= 0xffff) {
PUTS(fd, "\\u");
dump_hexadecimal(fd, ch, 4);
}
@@ -644,7 +645,7 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
PUTS(fd, "Current thread 0x");
else
PUTS(fd, "Thread 0x");
- dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(long)*2);
+ dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(unsigned long)*2);
PUTS(fd, " (most recent call first):\n");
}