diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2002-07-28 16:44:23 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-07-28 16:44:23 +0000 |
commit | 7bf8b9caa60efffdae10c7a9349674e27cb5f2b7 (patch) | |
tree | 96232b12aeba61c75ef17db3fe140650383230dc /Objects/stringobject.c | |
parent | c86f93ddaba02e1e2afc87ed6e4b69d49dd8f0c4 (diff) | |
download | cpython-7bf8b9caa60efffdae10c7a9349674e27cb5f2b7.tar.gz |
Fix the problem of not raising a TypeError exception when doing:
'%g' % '1'
'%d' % '1'
Add a test for these conditions
Fix the test so that if not exception is raise, this is a failure
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 83421a944c..c40bc18579 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3120,11 +3120,11 @@ formatfloat(char *buf, size_t buflen, int flags, worst case length = 3 + 10 (len of INT_MAX) + 1 = 14 (use 20)*/ char fmt[20]; double x; - v = PyNumber_Float(v); - if (!v) + x = PyFloat_AsDouble(v); + if (x == -1.0 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "float argument required"); return -1; - x = PyFloat_AS_DOUBLE(v); - Py_DECREF(v); + } if (prec < 0) prec = 6; if (type == 'f' && fabs(x)/1e25 >= 1e25) @@ -3299,11 +3299,11 @@ formatint(char *buf, size_t buflen, int flags, char fmt[64]; /* plenty big enough! */ long x; - v = PyNumber_Int(v); - if (!v) + x = PyInt_AsLong(v); + if (x == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "int argument required"); return -1; - x = PyInt_AS_LONG(v); - Py_DECREF(v); + } if (prec < 0) prec = 1; |