[Python-checkins] Fix compiler warnings in init_dump_ascii_wstr() (GH-22150)

Miss Islington (bot) webhook-mailer at python.org
Tue Sep 15 09:42:38 EDT 2020


https://github.com/python/cpython/commit/b2376f9141625dfa3844ef8a568c91e0f0fecd24
commit: b2376f9141625dfa3844ef8a568c91e0f0fecd24
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-09-09T03:31:25-07:00
summary:

Fix compiler warnings in init_dump_ascii_wstr() (GH-22150)


Fix GCC 9.3 (using -O3) warnings on x86:

initconfig.c: In function ‘init_dump_ascii_wstr’:
initconfig.c:2679:34: warning: format ‘%lc’ expects argument of type
‘wint_t’, but argument 2 has type ‘wchar_t’ {aka ‘long int’}
 2679 |             PySys_WriteStderr("%lc", ch);
initconfig.c:2682:38: warning: format ‘%x’ expects argument of type
‘unsigned int’, but argument 2 has type ‘wchar_t’ {aka ‘long int’}
 2682 |             PySys_WriteStderr("\\x%02x", ch);
initconfig.c:2686:38: warning: format ‘%x’ expects argument of type
‘unsigned int’, but argument 2 has type ‘wchar_t’ {aka ‘long int’}
 2686 |             PySys_WriteStderr("\\U%08x", ch);
initconfig.c:2690:38: warning: format ‘%x’ expects argument of type
‘unsigned int’, but argument 2 has type ‘wchar_t’ {aka ‘long int’}
 2690 |             PySys_WriteStderr("\\u%04x", ch);
(cherry picked from commit 640e8e1d5f61d5868453d992da04bf4741327748)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
M Python/initconfig.c

diff --git a/Python/initconfig.c b/Python/initconfig.c
index 9349fdd82504c..9887079a86fd1 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -2672,7 +2672,7 @@ init_dump_ascii_wstr(const wchar_t *str)
 
     PySys_WriteStderr("'");
     for (; *str != L'\0'; str++) {
-        wchar_t ch = *str;
+        unsigned int ch = (unsigned int)*str;
         if (ch == L'\'') {
             PySys_WriteStderr("\\'");
         } else if (0x20 <= ch && ch < 0x7f) {



More information about the Python-checkins mailing list