From e0b4532635c5ae04a51678bf81a0509b6e901cb3 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Fri, 13 Jan 2023 12:58:10 +0100 Subject: Check the pointer in AutoPointer before super It makes no sense to initialize the base class with a potentially invalid pointer. --- lib/ffi/autopointer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ffi/autopointer.rb b/lib/ffi/autopointer.rb index 679d7e6..6c6333c 100644 --- a/lib/ffi/autopointer.rb +++ b/lib/ffi/autopointer.rb @@ -76,9 +76,9 @@ module FFI # going to be useful if you subclass {AutoPointer}, and override # #release, which by default does nothing. def initialize(ptr, proc=nil, &block) + raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) || + ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) super(ptr.type_size, ptr) - raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \ - || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) @releaser = if proc if not proc.respond_to?(:call) -- cgit v1.2.1