[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Larry Hastings

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 1309fee48908 by Antoine Pitrou in branch 'default':
Close #19260: remove outdated comment in marshal.c
http://hg.python.org/cpython/rev/1309fee48908

--
nosy: +python-dev
resolution:  -> fixed
stage:  -> committed/rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Martin v . Löwis

Martin v. Löwis added the comment:

I agree that the comment can be removed. If the code is (now) statically 
type-safe, there is no point in keeping it.

--
nosy: +loewis

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Well, the comment should actually be removed, it's just pointless.

--
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Georg Brandl

Georg Brandl added the comment:

 The "rXXX" notation is reserved for SVN revision numbers, which are 
unambiguous.  The revision numbers in Mercurial are specific to each clone. 


Other than that, LGTM.

--
nosy: +georg.brandl

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19260] "int" comment in marshal.c is outdated

2013-10-14 Thread Larry Hastings

New submission from Larry Hastings:

In r_string() (read a string) in marshal.c we see this comment:

/* The result fits into int because it must be <=n. */
read = fread(p->buf, 1, n, p->fp);

This comment was first committed in r36501 by MvL.  Back then the "read" and 
"n" variables were int, but (of course) the return size of fread was size_t.  
Since then, both n and read have become ssize_t.

I suggest changing the wording slightly anyway, because I had to meditate on 
what the comment was originally trying to say.  I suggest:

/* The result fits into ssize_t because n is ssize_t. */

Patch appended too.  Bikeshedding away!

Should this be fixed in previous versions too?

--
files: larry.marshal.outdated.comment.r1.diff
keywords: patch
messages: 199883
nosy: larry
priority: normal
severity: normal
status: open
title: "int" comment in marshal.c is outdated
versions: Python 3.4
Added file: 
http://bugs.python.org/file32116/larry.marshal.outdated.comment.r1.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com