[Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c

Neal Norwitz nnorwitz at gmail.com
Thu Apr 20 09:00:07 CEST 2006


On 4/19/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>
> Somebody please correct me, but this still doesn't look right. As "len"
> includes the terminating null byte as returned from confstr, and as
> PyString_FromStringAndSize requires the number of characters *in*
> the string (i.e. excluding the terminating null byte), I think this
> should be
>
>                 if ((unsigned int)len >= sizeof(buffer)) {
>                   result = PyString_FromStringAndSize(NULL, len-1);
>                   if (result != NULL)
>                       confstr(name, PyString_AS_STRING(result), len);
>               }
>
> Also, for symmetry, I would like the second case to read
>
>              result = PyString_FromStringAndSize(buffer, len-1);

I couldn't determine you were wrong.  I tested your version with
valgrind and I set the buffer to 4 bytes to ensure the code was
exercised.  There were no complaints.  I'm not sure.  I found man
pages on a bunch of diff architectures, they seemed really
inconsistent and not explicit about what len should be.

It's probably safer to over allocate.  So I'm not sure what is the
best thing to do.  I didn't find one usage when searching just man
pages.  I wonder if anyone really uses this API?

n


More information about the Python-checkins mailing list