[macruby-changes] [5107] MacRuby/trunk/ext/socket/socket.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jan 3 04:55:58 PST 2011
Revision: 5107
http://trac.macosforge.org/projects/ruby/changeset/5107
Author: watson1978 at gmail.com
Date: 2011-01-03 04:55:53 -0800 (Mon, 03 Jan 2011)
Log Message:
-----------
Socket.getservbyport(port) will not accept the port with outside of uint16 range.
Test Script:
{{{
require 'socket'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
assert_raise(RangeError) { Socket.getservbyport(-1) }
assert_raise(RangeError) { Socket.getservbyport(2**16) }
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/ext/socket/socket.c
Modified: MacRuby/trunk/ext/socket/socket.c
===================================================================
--- MacRuby/trunk/ext/socket/socket.c 2011-01-03 11:33:43 UTC (rev 5106)
+++ MacRuby/trunk/ext/socket/socket.c 2011-01-03 12:55:53 UTC (rev 5107)
@@ -3241,8 +3241,14 @@
{
VALUE port, proto;
struct servent *sp;
+ long portnum;
rb_scan_args(argc, argv, "11", &port, &proto);
+ portnum = NUM2LONG(port);
+ if (portnum != (uint16_t)portnum) {
+ const char *s = portnum > 0 ? "big" : "small";
+ rb_raise(rb_eRangeError, "integer %ld too %s to convert into `int16_t'", portnum, s);
+ }
if (NIL_P(proto)) proto = rb_str_new2("tcp");
StringValue(proto);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110103/888f20ec/attachment.html>
More information about the macruby-changes
mailing list