Skip to content

Commit a0c8efd

Browse files
mgrojodgarske
authored andcommitted
Ada: fix wrapping of wolfSSL_ERR_error_string_n
Use unchecked conversion instead of type conversion to mimic C style conversion from int to unsigned long, avoiding the Ada overflow check that is raised when a negative value is converted to an unsigned type.
1 parent 0224ef3 commit a0c8efd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

wrapper/Ada/wolfssl.adb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
--
2121

22+
with Ada.Unchecked_Conversion;
2223
pragma Warnings (Off, "* is an internal GNAT unit");
2324
with GNAT.Sockets.Thin_Common;
2425
pragma Warnings (On, "* is an internal GNAT unit");
@@ -798,10 +799,15 @@ package body WolfSSL is
798799
S : String (1 .. Error_Message_Index'Last);
799800
B : Byte_Array (1 .. size_t (Error_Message_Index'Last));
800801
C : Natural;
802+
-- Use unchecked conversion instead of type conversion to mimic C style
803+
-- conversion from int to unsigned long, avoiding the Ada overflow check.
804+
function To_Unsigned_Long is new Ada.Unchecked_Conversion
805+
(Source => long,
806+
Target => unsigned_long);
801807
begin
802-
WolfSSL_Error_String (Error => unsigned_long (Code),
808+
WolfSSL_Error_String (Error => To_Unsigned_Long (long (Code)),
803809
Data => B,
804-
Size => unsigned_long (B'Last));
810+
Size => To_Unsigned_Long (long (B'Last)));
805811
Interfaces.C.To_Ada (Item => B,
806812
Target => S,
807813
Count => C,

0 commit comments

Comments
 (0)