Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 21092:53270d281bf0 legacy-trunk
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.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 28 Nov 2001 21:46:59 +0000 |
| parents | 47ea73fd7e6b |
| children | cdb70bf88db1 |
line wrap: on
line diff
--- a/Python/getargs.c Wed Nov 28 21:44:53 2001 +0000 +++ b/Python/getargs.c Wed Nov 28 21:46:59 2001 +0000 @@ -224,26 +224,27 @@ 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);
