Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b86f08f

Browse files
committed
faulthandler: enhance dump_ascii() to escape also non-printable ASCII
characters (U+0000..U+001f and U+007f).
1 parent 392f413 commit b86f08f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Python/traceback.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,16 @@ dump_ascii(int fd, PyObject *text)
541541
ch = PyUnicode_READ(kind, data, i);
542542
else
543543
ch = wstr[i];
544-
if (ch < 128) {
544+
if (' ' <= ch && ch <= 126) {
545+
/* printable ASCII character */
545546
char c = (char)ch;
546547
write(fd, &c, 1);
547548
}
548-
else if (ch < 0xff) {
549+
else if (ch <= 0xff) {
549550
PUTS(fd, "\\x");
550551
dump_hexadecimal(fd, ch, 2);
551552
}
552-
else if (ch < 0xffff) {
553+
else if (ch <= 0xffff) {
553554
PUTS(fd, "\\u");
554555
dump_hexadecimal(fd, ch, 4);
555556
}
@@ -644,7 +645,7 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
644645
PUTS(fd, "Current thread 0x");
645646
else
646647
PUTS(fd, "Thread 0x");
647-
dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(long)*2);
648+
dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(unsigned long)*2);
648649
PUTS(fd, " (most recent call first):\n");
649650
}
650651

0 commit comments

Comments
 (0)