fiddle icon indicating copy to clipboard operation
fiddle copied to clipboard

Unreachable code path in Fiddle::ValueUtil#wrap_arg

Open Maumagnaguagno opened this issue 2 years ago • 5 comments

In Fiddle::ValueUtil#wrap_arg there is a long case-when for arg with an unreachable code path. When arg and ty are of Array type, and ty[0] is TYPE_CHAR, there is another condition, for arg to be String at Line 101. Even if this condition is fixed, val is undefined at Line 102 for this method. https://github.com/ruby/fiddle/blob/04238cefed14a433f93909bd93dbe1d0a4efc47e/lib/fiddle/value.rb#L95-L106

Should Lines 100-103 be removed?

Maumagnaguagno avatar Mar 17 '23 07:03 Maumagnaguagno

Can you create a script that uses 101 and share it to us?

kou avatar Mar 17 '23 08:03 kou

require 'fiddle/value'

c = Class.new.extend(Fiddle::ValueUtil)
p c.wrap_arg(['55','0'],[Fiddle::TYPE_VOIDP]) # Line  99
p c.wrap_arg(['test'],[Fiddle::TYPE_CHAR])    # Line 106

Maumagnaguagno avatar Mar 17 '23 09:03 Maumagnaguagno

Ah, could you use normal API instead of directly using wrap_arg? It seems that lib/fiddle/struct.rb uses wrap_arg.

kou avatar Mar 17 '23 09:03 kou

Unfortunately I am not that familiar with Fiddle structs to make a valid minimal example to reach that point. I just noticed the loose variable val and that arg needs to be both Array and String at the same time.

Maumagnaguagno avatar Mar 17 '23 10:03 Maumagnaguagno

OK. I'll take a look at this later.

kou avatar Mar 20 '23 22:03 kou