Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0e5982

Browse files
committed
When errno is zero, avoid calling strerror() and use "Error" for the
message.
1 parent b0e5718 commit e0e5982

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Python/errors.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,20 @@ PyErr_SetFromErrnoWithFilename(exc, filename)
282282
char *filename;
283283
{
284284
PyObject *v;
285+
char *s;
285286
int i = errno;
286287
#ifdef EINTR
287288
if (i == EINTR && PyErr_CheckSignals())
288289
return NULL;
289290
#endif
291+
if (i == 0)
292+
s = "Error"; /* Sometimes errno didn't get set */
293+
else
294+
s = strerror(i);
290295
if (filename != NULL && Py_UseClassExceptionsFlag)
291-
v = Py_BuildValue("(iss)", i, strerror(i), filename);
296+
v = Py_BuildValue("(iss)", i, s, filename);
292297
else
293-
v = Py_BuildValue("(is)", i, strerror(i));
298+
v = Py_BuildValue("(is)", i, s);
294299
if (v != NULL) {
295300
PyErr_SetObject(exc, v);
296301
Py_DECREF(v);

0 commit comments

Comments
 (0)