summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-17 06:31:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-17 06:31:36 +0000
commit0bc53416909fe4470b9cac34072b0b3c555218a3 (patch)
tree83ed1268fc7353ad3d787e0068a6f6be935522f7 /ext/socket
parentf918d2b8e2f2736f57bd2ff01167702757e0a75b (diff)
option.c: single byte boolean
* ext/socket/option.c (sockopt_bool): relax boolean size to be one too not only sizeof(int). Winsock getsockopt() returns a single byte as a boolean socket option. [ruby-core:72730] [Bug #11958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/option.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/socket/option.c b/ext/socket/option.c
index d2da072..9fe21a1 100644
--- a/ext/socket/option.c
+++ b/ext/socket/option.c
@@ -302,10 +302,15 @@ static VALUE
sockopt_bool(VALUE self)
{
int i;
+ long len;
VALUE data = sockopt_data(self);
StringValue(data);
- check_size(RSTRING_LEN(data), sizeof(int));
- memcpy((char*)&i, RSTRING_PTR(data), sizeof(int));
+ len = RSTRING_LEN(data);
+ if (len == 1) {
+ return *RSTRING_PTR(data) == 0 ? Qfalse : Qtrue;
+ }
+ check_size(len, sizeof(int));
+ memcpy((char*)&i, RSTRING_PTR(data), len);
return i == 0 ? Qfalse : Qtrue;
}