summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/intobject.c24
-rw-r--r--Objects/longobject.c18
2 files changed, 23 insertions, 19 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 7404e98..e339085 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -208,10 +208,9 @@ PyInt_FromString(char *s, char **pend, int base)
return NULL;
}
else if (errno != 0) {
- PyOS_snprintf(buffer, sizeof(buffer),
- "int() literal too large: %.200s", s);
- PyErr_SetString(PyExc_ValueError, buffer);
- return NULL;
+ if (err_ovf("string/unicode conversion"))
+ return NULL;
+ return PyLong_FromString(s, pend, base);
}
if (pend)
*pend = end;
@@ -222,16 +221,19 @@ PyInt_FromString(char *s, char **pend, int base)
PyObject *
PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
{
- char buffer[256];
+ PyObject *result;
+ char *buffer = PyMem_MALLOC(length+1);
- if (length >= sizeof(buffer)) {
- PyErr_SetString(PyExc_ValueError,
- "int() literal too large to convert");
+ if (buffer == NULL)
return NULL;
- }
- if (PyUnicode_EncodeDecimal(s, length, buffer, NULL))
+
+ if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) {
+ PyMem_FREE(buffer);
return NULL;
- return PyInt_FromString(buffer, NULL, base);
+ }
+ result = PyInt_FromString(buffer, NULL, base);
+ PyMem_FREE(buffer);
+ return result;
}
#endif
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 35d1211..7374fce 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1123,17 +1123,19 @@ PyLong_FromString(char *str, char **pend, int base)
PyObject *
PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
{
- char buffer[256];
+ PyObject *result;
+ char *buffer = PyMem_MALLOC(length+1);
- if (length >= sizeof(buffer)) {
- PyErr_SetString(PyExc_ValueError,
- "long() literal too large to convert");
- return NULL;
- }
- if (PyUnicode_EncodeDecimal(u, length, buffer, NULL))
+ if (buffer == NULL)
return NULL;
- return PyLong_FromString(buffer, NULL, base);
+ if (PyUnicode_EncodeDecimal(u, length, buffer, NULL)) {
+ PyMem_FREE(buffer);
+ return NULL;
+ }
+ result = PyLong_FromString(buffer, NULL, base);
+ PyMem_FREE(buffer);
+ return result;
}
#endif