[Python-bugs-list] [ python-Bugs-811295 ] ntohs on Solaris can
return negative values
SourceForge.net
noreply at sourceforge.net
Tue Sep 23 13:23:49 EDT 2003
Bugs item #811295, was opened at 2003-09-23 13:23
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811295&group_id=5470
Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Nobody/Anonymous (nobody)
Summary: ntohs on Solaris can return negative values
Initial Comment:
On Solaris, socket.ntohs() can return a negative number
when the argument has bit 15 set. This is not according
to spec or intention or expectation. The bug is because
on Solaris, ntohs() is defined as a macro that returns
its argument unchanged, roughly:
#define ntohs(x) (x)
The socket extension casts the argument to (short); it
should use (unsigned short) or something similar.
Here's a program showing the problem (run this on
Solaris, or on another big-endian machine where ntohs()
is defined away):
import socket
print socket.ntohs(-1)
This should print 65535 but prints -1.
(Credit to Andrew Davis for finding this!)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811295&group_id=5470
More information about the Python-bugs-list
mailing list