Skip to content

Commit 493a8b7

Browse files
committed
Refactor wchar size
1 parent 97f7854 commit 493a8b7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/puppet/util/windows/registry.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module Registry
1717

1818
ERROR_NO_MORE_ITEMS = 259
1919

20+
WCHAR_SIZE = FFI.type_size(:wchar)
21+
2022
def root(name)
2123
Win32::Registry.const_get(name)
2224
rescue NameError
@@ -234,7 +236,7 @@ def read(key, name_ptr, *rtype)
234236

235237
string_length = 0
236238
# buffer is raw bytes, *not* chars - less a NULL terminator
237-
string_length = (byte_length / FFI.type_size(:wchar)) - 1 if byte_length > 0
239+
string_length = (byte_length / WCHAR_SIZE) - 1 if byte_length > 0
238240

239241
begin
240242
result = case type
@@ -278,7 +280,7 @@ def query_value_ex(key, name_ptr, &block)
278280

279281
if result != FFI::ERROR_SUCCESS
280282
# buffer is raw bytes, *not* chars - less a NULL terminator
281-
name_length = (name_ptr.size / FFI.type_size(:wchar)) - 1 if name_ptr.size > 0
283+
name_length = (name_ptr.size / WCHAR_SIZE) - 1 if name_ptr.size > 0
282284
msg = _("Failed to read registry value %{value} at %{key}") % { value: name_ptr.read_wide_string(name_length), key: key.keyname }
283285
raise Puppet::Util::Windows::Error.new(msg, result)
284286
end

0 commit comments

Comments
 (0)