From a41dedec645a0894d9173e5de0b502f727572f62 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 9 Apr 2025 23:54:13 +1200 Subject: Fixed RGB_Image size_t issue, RGB_Image/Bitmap preconditions --- spec/fltk-images-bitmaps.ads | 8 ++++---- spec/fltk-images-rgb.ads | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'spec') 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 -- cgit