Skip to content

Commit 083694e

Browse files
committed
use .null? to test NULL pointer returns
we were using `.nil?` in a couple of cases see #419 thanks dloebl
1 parent 80a222b commit 083694e

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master
44

5+
* improve NULL pointer handling [dloebl]
6+
57
## Version 2.2.4 (2025-06-05)
68

79
* fix write to target test with libvips 8.17 [jcupitt]

lib/vips/image.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ def self.new_from_array array, scale = 1, offset = 0
534534
end
535535

536536
image = Vips::Image.matrix_from_array width, height, array
537-
raise Vips::Error if image.nil?
538537

539538
image.mutate do |mutable|
540539
# be careful to set them as double
@@ -700,7 +699,7 @@ def write_to_target target, format_string, **opts
700699
def write_to_memory
701700
len = Vips::SizeStruct.new
702701
ptr = Vips.vips_image_write_to_memory self, len
703-
raise Vips::Error if ptr.nil?
702+
raise Vips::Error if ptr.null?
704703

705704
# wrap up as an autopointer
706705
ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE)

lib/vips/interpolate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ManagedStruct < Vips::Object::ManagedStruct
5050
def initialize name
5151
name = name.to_s if name.is_a? Symbol
5252
pointer = Vips.vips_interpolate_new name
53-
raise Vips::Error if pointer.nil?
53+
raise Vips::Error if pointer.null?
5454

5555
super(pointer)
5656
end

spec/image_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
expect(x.avg).to eq(128)
7777
end
7878

79+
it "will raise VipsError for invalid image files" do
80+
img = Vips::Image.new_from_file simg("coffee.gif")
81+
expect { img.write_to_memory }.to raise_exception(Vips::Error)
82+
end
83+
7984
it "throws an error when trying to load an image from memory with unknown size" do
8085
data = FFI::Pointer.new(1)
8186
expect { Vips::Image.new_from_memory(data, 16, 16, 1, :uchar) }.to raise_error(Vips::Error)

spec/samples/coffee.gif

2.05 KB
Loading

spec/vips_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,10 @@
193193

194194
expect { black.crop(10, 10, 1, 1) }.to raise_exception(Vips::Error)
195195
end
196+
197+
it "can throw errors for bad interpolations" do
198+
expect { Vips::Interpolate.new "banana" }.to raise_exception(Vips::Error)
199+
end
200+
196201
end
197202
end

0 commit comments

Comments
 (0)