aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-04-09 23:54:13 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2025-04-09 23:54:13 +1200
commita41dedec645a0894d9173e5de0b502f727572f62 (patch)
tree808cba7c49925deca77b738eaa69e05132bbc834
parent8d8ecd6db517cb208ef165785575287568e5a175 (diff)
Fixed RGB_Image size_t issue, RGB_Image/Bitmap preconditions
-rw-r--r--body/fltk-images-bitmaps.adb14
-rw-r--r--body/fltk-images-rgb.adb10
-rw-r--r--spec/fltk-images-bitmaps.ads8
-rw-r--r--spec/fltk-images-rgb.ads13
4 files changed, 26 insertions, 19 deletions
diff --git a/body/fltk-images-bitmaps.adb b/body/fltk-images-bitmaps.adb
index cfb63d7..4597151 100644
--- a/body/fltk-images-bitmaps.adb
+++ b/body/fltk-images-bitmaps.adb
@@ -118,7 +118,9 @@ package body FLTK.Images.Bitmaps is
begin
return This : Bitmap do
This.Void_Ptr := new_fl_bitmap
- (Storage.To_Integer (Data (Data'First)'Address),
+ ((if Data'Length > 0
+ then Storage.To_Integer (Data (Data'First)'Address)
+ else Null_Pointer),
Interfaces.C.int (Width),
Interfaces.C.int (Height));
end return;
@@ -135,13 +137,13 @@ package body FLTK.Images.Bitmaps is
-- Contracts --
- function To_Next_Byte
+ function Bytes_Needed
(Bits : in Natural)
return Natural is
begin
- return Integer (Float'Ceiling (Float (Bits) / Float (Color_Component_Array'Component_Size)))
- * Color_Component_Array'Component_Size;
- end To_Next_Byte;
+ return Integer (Float'Ceiling
+ (Float (Bits) / Float (Color_Component_Array'Component_Size)));
+ end Bytes_Needed;
@@ -191,7 +193,7 @@ package body FLTK.Images.Bitmaps is
(This : in Bitmap)
return Natural is
begin
- return To_Next_Byte (This.Get_W) * This.Get_H;
+ return Bytes_Needed (This.Get_W) * This.Get_H;
end Data_Size;
diff --git a/body/fltk-images-rgb.adb b/body/fltk-images-rgb.adb
index ce512cd..00fc1ed 100644
--- a/body/fltk-images-rgb.adb
+++ b/body/fltk-images-rgb.adb
@@ -159,7 +159,9 @@ package body FLTK.Images.RGB is
begin
return This : RGB_Image do
This.Void_Ptr := new_fl_rgb_image
- (Storage.To_Integer (Data (Data'First)'Address),
+ ((if Data'Length > 0
+ then Storage.To_Integer (Data (Data'First)'Address)
+ else Null_Pointer),
Interfaces.C.int (Width),
Interfaces.C.int (Height),
Interfaces.C.int (Depth),
@@ -192,14 +194,14 @@ package body FLTK.Images.RGB is
-- Static Settings --
function Get_Max_Size
- return Natural is
+ return Size_Type is
begin
- return Natural (fl_rgb_image_get_max_size);
+ return Size_Type (fl_rgb_image_get_max_size);
end Get_Max_Size;
procedure Set_Max_Size
- (Value : in Natural) is
+ (Value : in Size_Type) is
begin
fl_rgb_image_set_max_size (Interfaces.C.size_t (Value));
end Set_Max_Size;
diff --git a/spec/fltk-images-bitmaps.ads b/spec/fltk-images-bitmaps.ads
index b31885c..73afc62 100644
--- a/spec/fltk-images-bitmaps.ads
+++ b/spec/fltk-images-bitmaps.ads
@@ -15,9 +15,9 @@ package FLTK.Images.Bitmaps is
- -- Rounds a number of bits up to the next byte boundary.
+ -- Calculates the bytes needed to hold a given number of bits.
- function To_Next_Byte
+ function Bytes_Needed
(Bits : in Natural)
return Natural;
@@ -33,7 +33,7 @@ package FLTK.Images.Bitmaps is
(Data : in Color_Component_Array;
Width, Height : in Natural)
return Bitmap
- with Pre => Data'Length = To_Next_Byte (Width) * Height;
+ with Pre => Data'Length >= Bytes_Needed (Width) * Height;
end Forge;
@@ -123,7 +123,7 @@ private
(This : in out Bitmap);
- pragma Inline (To_Next_Byte);
+ pragma Inline (Bytes_Needed);
pragma Inline (Copy);
diff --git a/spec/fltk-images-rgb.ads b/spec/fltk-images-rgb.ads
index daa31c6..242098a 100644
--- a/spec/fltk-images-rgb.ads
+++ b/spec/fltk-images-rgb.ads
@@ -6,7 +6,8 @@
with
- FLTK.Images.Pixmaps;
+ FLTK.Images.Pixmaps,
+ System.Storage_Elements;
package FLTK.Images.RGB is
@@ -19,16 +20,18 @@ package FLTK.Images.RGB is
type RGB_Image_Array is array (Positive range <>) of RGB_Image;
+ type Size_Type is mod 2 ** System.Storage_Elements.Integer_Address'Size;
+
-- Static Settings --
function Get_Max_Size
- return Natural;
+ return Size_Type;
procedure Set_Max_Size
- (Value : in Natural);
+ (Value : in Size_Type);
@@ -45,8 +48,8 @@ package FLTK.Images.RGB is
Line_Size : in Natural := 0)
return RGB_Image
with Pre => (if Line_Size = 0
- then Data'Length = Width * Height * Depth
- else Data'Length = Line_Size * Height)
+ then Data'Length >= Width * Height * Depth
+ else Data'Length >= Line_Size * Height)
and Data'Length <= Get_Max_Size;
function Create