Commits

Guido van Rossum  committed c80321c

When errno is zero, avoid calling strerror() and use "Error" for the
message.

  • Participants
  • Parent commits 9f135b3
  • Branches legacy-trunk

Comments (0)

Files changed (1)

File Python/errors.c

 	char *filename;
 {
 	PyObject *v;
+	char *s;
 	int i = errno;
 #ifdef EINTR
 	if (i == EINTR && PyErr_CheckSignals())
 		return NULL;
 #endif
+	if (i == 0)
+		s = "Error"; /* Sometimes errno didn't get set */
+	else
+		s = strerror(i);
 	if (filename != NULL && Py_UseClassExceptionsFlag)
-		v = Py_BuildValue("(iss)", i, strerror(i), filename);
+		v = Py_BuildValue("(iss)", i, s, filename);
 	else
-		v = Py_BuildValue("(is)", i, strerror(i));
+		v = Py_BuildValue("(is)", i, s);
 	if (v != NULL) {
 		PyErr_SetObject(exc, v);
 		Py_DECREF(v);