From a0c8efdffecac230bcfbd2d12ee1d882f1d7c4b7 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 10 Aug 2025 20:17:13 +0200 Subject: [PATCH] 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. --- wrapper/Ada/wolfssl.adb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wrapper/Ada/wolfssl.adb b/wrapper/Ada/wolfssl.adb index 9bdd07afd..2f7caba0b 100644 --- a/wrapper/Ada/wolfssl.adb +++ b/wrapper/Ada/wolfssl.adb @@ -19,6 +19,7 @@ -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA -- +with Ada.Unchecked_Conversion; pragma Warnings (Off, "* is an internal GNAT unit"); with GNAT.Sockets.Thin_Common; pragma Warnings (On, "* is an internal GNAT unit"); @@ -798,10 +799,15 @@ package body WolfSSL is S : String (1 .. Error_Message_Index'Last); B : Byte_Array (1 .. size_t (Error_Message_Index'Last)); C : Natural; + -- Use unchecked conversion instead of type conversion to mimic C style + -- conversion from int to unsigned long, avoiding the Ada overflow check. + function To_Unsigned_Long is new Ada.Unchecked_Conversion + (Source => long, + Target => unsigned_long); begin - WolfSSL_Error_String (Error => unsigned_long (Code), + WolfSSL_Error_String (Error => To_Unsigned_Long (long (Code)), Data => B, - Size => unsigned_long (B'Last)); + Size => To_Unsigned_Long (long (B'Last))); Interfaces.C.To_Ada (Item => B, Target => S, Count => C,