Skip to content

Commit

Permalink
Refactor wchar size
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcooper committed Jan 10, 2024
1 parent 97f7854 commit 493a8b7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/util/windows/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Registry

ERROR_NO_MORE_ITEMS = 259

WCHAR_SIZE = FFI.type_size(:wchar)

def root(name)
Win32::Registry.const_get(name)
rescue NameError
Expand Down Expand Up @@ -234,7 +236,7 @@ def read(key, name_ptr, *rtype)

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

begin
result = case type
Expand Down Expand Up @@ -278,7 +280,7 @@ def query_value_ex(key, name_ptr, &block)

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

0 comments on commit 493a8b7

Please sign in to comment.