diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 21:46:59 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 21:46:59 (GMT) |
commit | f16e05e7ecdba12180a0e64de22190b617a639bb (patch) | |
tree | 0223d704b072a16acc87a6c105c4329a78d03050 | |
parent | 5d3d134d560d24a9e6b9d65dd814542605c0b152 (diff) | |
download | cpython-f16e05e7ecdba12180a0e64de22190b617a639bb.zip cpython-f16e05e7ecdba12180a0e64de22190b617a639bb.tar.gz cpython-f16e05e7ecdba12180a0e64de22190b617a639bb.tar.bz2 |
Use PyOS_snprintf() at some cost even though it was correct before.
seterror() uses a char array and a pointer to the current position in
that array. Use snprintf() and compute the amount of space left in
the buffer based on the current pointer position.
-rw-r--r-- | Python/getargs.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index b7bbb5a..8c4b039 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -224,26 +224,27 @@ seterror(int iarg, char *msg, int *levels, char *fname, char *message) if (PyErr_Occurred()) return; else if (message == NULL) { - /* XXX snprintf */ if (fname != NULL) { - sprintf(p, "%.200s() ", fname); + PyOS_snprintf(p, sizeof(buf), "%.200s() ", fname); p += strlen(p); } if (iarg != 0) { - sprintf(p, "argument %d", iarg); + PyOS_snprintf(p, sizeof(buf) - (buf - p), + "argument %d", iarg); i = 0; p += strlen(p); while (levels[i] > 0 && (int)(p-buf) < 220) { - sprintf(p, ", item %d", levels[i]-1); + PyOS_snprintf(p, sizeof(buf) - (buf - p), + ", item %d", levels[i]-1); p += strlen(p); i++; } } else { - sprintf(p, "argument"); + PyOS_snprintf(p, sizeof(buf) - (buf - p), "argument"); p += strlen(p); } - sprintf(p, " %.256s", msg); + PyOS_snprintf(p, sizeof(buf) - (buf - p), " %.256s", msg); message = buf; } PyErr_SetString(PyExc_TypeError, message); |