diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-24 07:41:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-24 07:41:17 +0000 |
commit | 360c66732c145d46fcf8fdf418737d77c2fdfbe2 (patch) | |
tree | af247edafc6a261deca242fce069da2bd11a007f | |
parent | 79e880c90df6938e8226336a883d1973031da3df (diff) | |
download | ruby-360c66732c145d46fcf8fdf418737d77c2fdfbe2.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/win32/lib/win32/registry.rb | 9 |
2 files changed, 11 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Tue Sep 24 16:41:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * ext/win32/lib/win32/registry.rb (Win32::Registry#each_value): encode diff --git a/ext/win32/lib/win32/registry.rb b/ext/win32/lib/win32/registry.rb index 668f573edb..74cc77dc9f 100644 --- a/ext/win32/lib/win32/registry.rb +++ b/ext/win32/lib/win32/registry.rb @@ -725,11 +725,14 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr # 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.microsoft.com/library/en-us/sysinfo/base/pr 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 # |