Skip to content

Commit e3645ba

Browse files
joshcoopergithub-actions[bot]
authored andcommitted
Refactor wchar size
(cherry picked from commit 493a8b7)
1 parent 3ccc40e commit e3645ba

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
@@ -15,6 +15,8 @@ module Registry
1515

1616
ERROR_NO_MORE_ITEMS = 259
1717

18+
WCHAR_SIZE = FFI.type_size(:wchar)
19+
1820
def root(name)
1921
Win32::Registry.const_get(name)
2022
rescue NameError
@@ -235,7 +237,7 @@ def read(key, name_ptr, *rtype)
235237

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

240242
begin
241243
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)