Skip to content

Commit 6f24e7c

Browse files
committed
Use pointers with a known #total for #setproctitle
1 parent 23acb46 commit 6f24e7c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/ruby/truffleruby/core/process.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ def self.setproctitle_darwin(title)
215215
argv0_address = Truffle::POSIX._NSGetArgv.read_pointer.read_pointer
216216

217217
@_argv0_max_length ||= argv0_address.read_string.bytesize
218+
argv0_address = argv0_address.slice(0, @_argv0_max_length)
218219

219220
new_title = setproctitle_truncate_title(title, @_argv0_max_length)
220-
argv0_address.write_string new_title
221+
argv0_address.write_bytes new_title
221222
end
222223
private_class_method :setproctitle_darwin
223224

@@ -259,8 +260,8 @@ def self.setproctitle_linux_from_proc_maps(title)
259260

260261
new_title = setproctitle_truncate_title(title, @_argv0_max_length)
261262

262-
argv0_ptr = FFI::Pointer.new(:char, @_argv0_address)
263-
argv0_ptr.write_string(new_title)
263+
argv0_ptr = FFI::Pointer.new(:char, @_argv0_address).slice(0, @_argv0_max_length)
264+
argv0_ptr.write_bytes(new_title)
264265

265266
new_command = File.binread('/proc/self/cmdline')
266267
raise 'failed' unless new_command.start_with?(new_title)

0 commit comments

Comments
 (0)