diff options
author | Barry Warsaw <barry@python.org> | 2001-08-24 18:34:26 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-08-24 18:34:26 (GMT) |
commit | 7ce3694a527afe425a2b9df65c049b0ef4e75960 (patch) | |
tree | 089937f432c69e85afbfc8308d5ebc86dd2c2c49 /Objects/rangeobject.c | |
parent | dadace004b4b94dcc4437bafc9c8407fbb1bed74 (diff) | |
download | cpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.zip cpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.tar.gz cpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.tar.bz2 |
repr's converted to using PyString_FromFormat() instead of sprintf'ing
into a hardcoded char* buffer.
Closes patch #454743.
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 5ad86ed..24765f4 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -126,30 +126,30 @@ range_length(rangeobject *r) static PyObject * range_repr(rangeobject *r) { - /* buffers must be big enough to hold 3 longs + an int + - * a bit of "(xrange(...) * ...)" text. - */ - char buf1[250]; - char buf2[250]; - + PyObject *rtn; + if (r->start == 0 && r->step == 1) - sprintf(buf1, "xrange(%ld)", r->start + r->len * r->step); + rtn = PyString_FromFormat("xrange(%ld)", + r->start + r->len * r->step); else if (r->step == 1) - sprintf(buf1, "xrange(%ld, %ld)", - r->start, - r->start + r->len * r->step); + rtn = PyString_FromFormat("xrange(%ld, %ld)", + r->start, + r->start + r->len * r->step); else - sprintf(buf1, "xrange(%ld, %ld, %ld)", - r->start, - r->start + r->len * r->step, - r->step); - - if (r->reps != 1) - sprintf(buf2, "(%s * %d)", buf1, r->reps); - - return PyString_FromString(r->reps == 1 ? buf1 : buf2); + rtn = PyString_FromFormat("xrange(%ld, %ld, %ld)", + r->start, + r->start + r->len * r->step, + r->step); + if (r->reps != 1) { + PyObject *extra = PyString_FromFormat( + "(%s * %d)", + PyString_AS_STRING(rtn), r->reps); + Py_DECREF(rtn); + rtn = extra; + } + return rtn; } static PyObject * |