summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-11-28 20:55:34 (GMT)
committerBarry Warsaw <barry@python.org>2001-11-28 20:55:34 (GMT)
commit6197509f2487a07af8ebfda75ac500aaa42df780 (patch)
tree60dbf74ab9fd5aeba2d19b69826a0f2932d83184 /Objects/intobject.c
parentaf8aef9ee241474c8764cb25319e17986cfb2ef6 (diff)
downloadcpython-6197509f2487a07af8ebfda75ac500aaa42df780.zip
cpython-6197509f2487a07af8ebfda75ac500aaa42df780.tar.gz
cpython-6197509f2487a07af8ebfda75ac500aaa42df780.tar.bz2
PyInt_FromString(), int_repr(), int_oct(), int_hex(): Conversion of
sprintf() to PyOS_snprintf() for buffer overrun avoidance.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index bb5ad16..aba9f51 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -198,12 +198,14 @@ PyInt_FromString(char *s, char **pend, int base)
end++;
if (*end != '\0') {
bad:
- sprintf(buffer, "invalid literal for int(): %.200s", s);
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "invalid literal for int(): %.200s", s);
PyErr_SetString(PyExc_ValueError, buffer);
return NULL;
}
else if (errno != 0) {
- sprintf(buffer, "int() literal too large: %.200s", s);
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "int() literal too large: %.200s", s);
PyErr_SetString(PyExc_ValueError, buffer);
return NULL;
}
@@ -257,7 +259,7 @@ static PyObject *
int_repr(PyIntObject *v)
{
char buf[20];
- sprintf(buf, "%ld", v->ob_ival);
+ PyOS_snprintf(buf, sizeof(buf), "%ld", v->ob_ival);
return PyString_FromString(buf);
}
@@ -820,7 +822,7 @@ int_oct(PyIntObject *v)
if (x == 0)
strcpy(buf, "0");
else
- sprintf(buf, "0%lo", x);
+ PyOS_snprintf(buf, sizeof(buf), "0%lo", x);
return PyString_FromString(buf);
}
@@ -829,7 +831,7 @@ int_hex(PyIntObject *v)
{
char buf[100];
long x = v -> ob_ival;
- sprintf(buf, "0x%lx", x);
+ PyOS_snprintf(buf, sizeof(buf), "0x%lx", x);
return PyString_FromString(buf);
}