Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(122991)

#28332: silent truncations in socket.htons and socket.ntohs

Can't Edit
Can't Publish+Mail
Start Review
Created:
3 years, 1 month ago by orenmn
Modified:
3 years, 1 month ago
Reviewers:
storchaka+cpython
CC:
devnull_psf.upfronthosting.co.za, storchaka, Oren Milman
Visibility:
Public.

Patch Set 1 #

Total comments: 6

Patch Set 2 #

Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Doc/library/socket.rst View 1 2 chunks +12 lines, -0 lines 0 comments Download
Lib/test/test_socket.py View 1 1 chunk +18 lines, -8 lines 0 comments Download
Modules/socketmodule.c View 1 2 chunks +40 lines, -8 lines 0 comments Download

Messages

Total messages: 2
storchaka
https://bugs.python.org/review/28332/diff/18723/Doc/library/socket.rst File Doc/library/socket.rst (right): https://bugs.python.org/review/28332/diff/18723/Doc/library/socket.rst#newcode667 Doc/library/socket.rst:667: Note that in case *x* does not fit in ...
3 years, 1 month ago #1
Oren Milman
3 years, 1 month ago #2
http://bugs.python.org/review/28332/diff/18723/Modules/socketmodule.c
File Modules/socketmodule.c (right):

http://bugs.python.org/review/28332/diff/18723/Modules/socketmodule.c#newcode...
Modules/socketmodule.c:5522: x2 = (long)ntohs((unsigned short)x1);
On 2016/10/01 21:37:42, storchaka wrote:
> What is the reason of changing (unsigned int) to (long)?

ntohs returns uint16_t, and x2 is long, so we have to cast from (smaller)
unsigned to signed.
ISTM that to make all compilers happy, we should explicitly cast to the (bigger)
signed, as we know the casting is guaranteed to not truncate.
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+