Larry Hastings added the comment:

Martin: The code is not statically type-safe, but it is mechanically safe, 
which I think is why you wrote the comment in the first place.

The return value of fread() is size_t, but the "read" variable is Py_ssize_t.  
So the function *could* theoretically return a value that would overflow the 
variable.  However, this can't happen in practice because the input size ("n") 
is also Py_ssize_t.  And fread() will never return a number larger than the 
number of bytes requested.  QED the function will never return a number larger 
than one that could be stored in Py_ssize_t.

If the comment originally had merit, then it still has merit.  It was referring 
to this exact same situation, except back then the "n" and "read" variables 
were both type "int".  They were both changed to "Py_ssize_t" some time ago but 
the comment was not updated.

Since Martin contributed the original code and comment I leave it to him to 
decide its fate, Antoine's shooting-from-the-hip aside.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19260>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to