mirror of https://github.com/python/cpython
Issue #8013: Fixed time.asctime segfault when OS's asctime fails
This commit is contained in:
parent
ece919eb0f
commit
e2dc082294
|
@ -122,6 +122,9 @@ class TimeTestCase(unittest.TestCase):
|
||||||
def test_asctime(self):
|
def test_asctime(self):
|
||||||
time.asctime(time.gmtime(self.t))
|
time.asctime(time.gmtime(self.t))
|
||||||
self.assertRaises(TypeError, time.asctime, 0)
|
self.assertRaises(TypeError, time.asctime, 0)
|
||||||
|
self.assertRaises(TypeError, time.asctime, ())
|
||||||
|
self.assertRaises(ValueError, time.asctime,
|
||||||
|
(12345, 1, 0, 0, 0, 0, 0, 0, 0))
|
||||||
|
|
||||||
def test_asctime_bounding_check(self):
|
def test_asctime_bounding_check(self):
|
||||||
self._bounds_checking(time.asctime)
|
self._bounds_checking(time.asctime)
|
||||||
|
|
|
@ -620,6 +620,10 @@ time_asctime(PyObject *self, PyObject *args)
|
||||||
} else if (!gettmarg(tup, &buf) || !checktm(&buf))
|
} else if (!gettmarg(tup, &buf) || !checktm(&buf))
|
||||||
return NULL;
|
return NULL;
|
||||||
p = asctime(&buf);
|
p = asctime(&buf);
|
||||||
|
if (p == NULL) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "invalid time");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (p[24] == '\n')
|
if (p[24] == '\n')
|
||||||
p[24] = '\0';
|
p[24] = '\0';
|
||||||
return PyUnicode_FromString(p);
|
return PyUnicode_FromString(p);
|
||||||
|
|
Loading…
Reference in New Issue