From 0bc53416909fe4470b9cac34072b0b3c555218a3 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 17 Jan 2016 06:31:36 +0000 Subject: 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 --- ext/socket/option.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ext/socket/option.c') diff --git a/ext/socket/option.c b/ext/socket/option.c index d2da072ad7..9fe21a12c1 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; } -- cgit v1.2.3