Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 726357f

Browse files
authored
use .null? to test NULL pointer returns (#420)
* use `.null?` to test NULL pointer returns we were using `.nil?` in a couple of cases see #419 thanks dloebl * fix a rcop fail * add a null check to matrix_from_array for safety * and bump version
1 parent 80a222b commit 726357f

File tree

8 files changed

+18
-7
lines changed

8 files changed

+18
-7
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]

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.4
1+
2.2.5

‎lib/vips/image.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ def self.new_from_source source, option_string, **opts
471471
def self.matrix_from_array width, height, array
472472
ptr = FFI::MemoryPointer.new :double, array.length
473473
ptr.write_array_of_double array
474-
image = Vips.vips_image_new_matrix_from_array width, height,
474+
img_ptr = Vips.vips_image_new_matrix_from_array width, height,
475475
ptr, array.length
476-
Vips::Image.new image
476+
raise Vips::Error if img_ptr.null?
477+
Vips::Image.new img_ptr
477478
end
478479

479480
# Create a new Image from a 1D or 2D array. A 1D array becomes an
@@ -534,7 +535,6 @@ def self.new_from_array array, scale = 1, offset = 0
534535
end
535536

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

539539
image.mutate do |mutable|
540540
# be careful to set them as double
@@ -700,7 +700,7 @@ def write_to_target target, format_string, **opts
700700
def write_to_memory
701701
len = Vips::SizeStruct.new
702702
ptr = Vips.vips_image_write_to_memory self, len
703-
raise Vips::Error if ptr.nil?
703+
raise Vips::Error if ptr.null?
704704

705705
# wrap up as an autopointer
706706
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

‎lib/vips/version.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Vips
2-
VERSION = "2.2.4"
2+
VERSION = "2.2.5"
33
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,9 @@
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
196200
end
197201
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /