From: Skip Montanaro Date: Tue, 18 Apr 2006 00:49:49 +0000 (+0000) Subject: reset errno before calling confstr - use confstr() doc to simplify checks afterwards X-Git-Tag: v2.5a2~148 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd527fcbcd484c1d4e29798c59ed45452c288eba;p=python reset errno before calling confstr - use confstr() doc to simplify checks afterwards --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 53f35da427..d91d8b5eec 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6812,17 +6812,19 @@ posix_confstr(PyObject *self, PyObject *args) char buffer[64]; if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) { - int len = confstr(name, buffer, sizeof(buffer)); + int len; errno = 0; - if (len == 0) { - if (errno != 0) - posix_error(); - else - result = PyString_FromString(""); + len = confstr(name, buffer, sizeof(buffer)); + + if (len == -1) { + posix_error(); + } + else if (len == 0) { + result = PyString_FromString(""); } else { - if (len >= sizeof(buffer)) { + if ((unsigned int)len >= sizeof(buffer)) { result = PyString_FromStringAndSize(NULL, len); if (result != NULL) confstr(name, PyString_AS_STRING(result), len+1);