ruby-changes:30952
From: nobu <ko1@a...>
Date: Tue, 24 Sep 2013 16:41:21 +0900 (JST)
Subject: [ruby-changes:30952] nobu:r43031 (trunk): win32/registry.rb: size in bytes
nobu 2013-09-24 16:41:17 +0900 (Tue, 24 Sep 2013) New Revision: 43031 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43031 Log: win32/registry.rb: size in bytes * ext/win32/lib/win32/registry.rb (Win32::Registry#write): data size is in bytes, not chars. terminators should be placed automatically. Modified files: trunk/ChangeLog trunk/ext/win32/lib/win32/registry.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43030) +++ ChangeLog (revision 43031) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 24 16:41:15 2013 Nobuyoshi Nakada <nobu@r...> + + * ext/win32/lib/win32/registry.rb (Win32::Registry#write): data size + is in bytes, not chars. terminators should be placed automatically. + Tue Sep 24 16:39:36 2013 Nobuyoshi Nakada <nobu@r...> * ext/win32/lib/win32/registry.rb (Win32::Registry#each_value): encode Index: ext/win32/lib/win32/registry.rb =================================================================== --- ext/win32/lib/win32/registry.rb (revision 43030) +++ ext/win32/lib/win32/registry.rb (revision 43031) @@ -725,11 +725,14 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L725 # method returns. # def write(name, type, data) + termsize = 0 case type when REG_SZ, REG_EXPAND_SZ - data = data.to_s + "\0" + data = data.encode(WCHAR) + termsize = WCHAR_SIZE when REG_MULTI_SZ - data = data.to_a.join("\0") + "\0\0" + data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL + termsize = WCHAR_SIZE when REG_BINARY data = data.to_s when REG_DWORD @@ -741,7 +744,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L744 else raise TypeError, "Unsupported type #{type}" end - API.SetValue(@hkey, name, type, data, data.length) + API.SetValue(@hkey, name, type, data, data.bytesize + termsize) end # -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/