Skip to content

Commit bb404e8

Browse files
author
martin.v.loewis
committed
Merged revisions 62199 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r62199 | martin.v.loewis | 2008-04-07 05:08:28 +0200 (Mo, 07 Apr 2008) | 2 lines Bug #2388: Fix gcc warnings when compiling with --enable-unicode=ucs4. ........ git-svn-id: http://svn.python.org/projects/python/branches/py3k@62201 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 7b46181 commit bb404e8

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

Objects/stringlib/formatter.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,19 @@ FORMAT_STRING(PyObject* value, PyObject* args)
785785
break;
786786
default:
787787
/* unknown */
788-
PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
789-
format.type);
788+
#if STRINGLIB_IS_UNICODE
789+
/* If STRINGLIB_CHAR is Py_UNICODE, %c might be out-of-range,
790+
hence the two cases. If it is char, gcc complains that the
791+
condition below is always true, hence the ifdef. */
792+
if (format.type > 32 && format.type <128)
793+
#endif
794+
PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
795+
(char)format.type);
796+
#if STRINGLIB_IS_UNICODE
797+
else
798+
PyErr_Format(PyExc_ValueError, "Unknown conversion type '\\x%x'",
799+
(unsigned int)format.type);
800+
#endif
790801
goto done;
791802
}
792803

Objects/stringlib/string_format.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,17 @@ do_conversion(PyObject *obj, STRINGLIB_CHAR conversion)
740740
case 's':
741741
return STRINGLIB_TOSTR(obj);
742742
default:
743-
PyErr_Format(PyExc_ValueError,
744-
"Unknown converion specifier %c",
745-
conversion);
743+
if (conversion > 32 && conversion < 127) {
744+
/* It's the ASCII subrange; casting to char is safe
745+
(assuming the execution character set is an ASCII
746+
superset). */
747+
PyErr_Format(PyExc_ValueError,
748+
"Unknown conversion specifier %c",
749+
(char)conversion);
750+
} else
751+
PyErr_Format(PyExc_ValueError,
752+
"Unknown conversion specifier \\x%x",
753+
(unsigned int)conversion);
746754
return NULL;
747755
}
748756
}

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8895,7 +8895,7 @@ PyObject *PyUnicode_Format(PyObject *format,
88958895
if (!isnumok) {
88968896
PyErr_Format(PyExc_TypeError,
88978897
"%%%c format: a number is required, "
8898-
"not %.200s", c, Py_TYPE(v)->tp_name);
8898+
"not %.200s", (char)c, Py_TYPE(v)->tp_name);
88998899
goto onError;
89008900
}
89018901
if (flags & F_ZERO)

0 commit comments

Comments
 (0)