summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-04-07 03:08:28 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-04-07 03:08:28 (GMT)
commitd918e4e068f22c3e79c771c27be3c8f91a9e0446 (patch)
tree5e5c2f72880c5a520db3b2a5b22635ba42983716 /Objects/stringlib
parent295814e4634b7130dc0c58bc1a9d91c14cbe804a (diff)
downloadcpython-d918e4e068f22c3e79c771c27be3c8f91a9e0446.zip
cpython-d918e4e068f22c3e79c771c27be3c8f91a9e0446.tar.gz
cpython-d918e4e068f22c3e79c771c27be3c8f91a9e0446.tar.bz2
Bug #2388: Fix gcc warnings when compiling with --enable-unicode=ucs4.
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/formatter.h15
-rw-r--r--Objects/stringlib/string_format.h14
2 files changed, 24 insertions, 5 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index 3ca14fa..531bc22 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -785,8 +785,19 @@ FORMAT_STRING(PyObject* value, PyObject* args)
break;
default:
/* unknown */
- PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
- format.type);
+ #if STRINGLIB_IS_UNICODE
+ /* If STRINGLIB_CHAR is Py_UNICODE, %c might be out-of-range,
+ hence the two cases. If it is char, gcc complains that the
+ condition below is always true, hence the ifdef. */
+ if (format.type > 32 && format.type <128)
+ #endif
+ PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
+ (char)format.type);
+ #if STRINGLIB_IS_UNICODE
+ else
+ PyErr_Format(PyExc_ValueError, "Unknown conversion type '\\x%x'",
+ (unsigned int)format.type);
+ #endif
goto done;
}
diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h
index 214b7b3..be8e8080 100644
--- a/Objects/stringlib/string_format.h
+++ b/Objects/stringlib/string_format.h
@@ -740,9 +740,17 @@ do_conversion(PyObject *obj, STRINGLIB_CHAR conversion)
case 's':
return STRINGLIB_TOSTR(obj);
default:
- PyErr_Format(PyExc_ValueError,
- "Unknown converion specifier %c",
- conversion);
+ if (conversion > 32 && conversion < 127) {
+ /* It's the ASCII subrange; casting to char is safe
+ (assuming the execution character set is an ASCII
+ superset). */
+ PyErr_Format(PyExc_ValueError,
+ "Unknown conversion specifier %c",
+ (char)conversion);
+ } else
+ PyErr_Format(PyExc_ValueError,
+ "Unknown conversion specifier \\x%x",
+ (unsigned int)conversion);
return NULL;
}
}