When a hostname has more than 1024 characters, Constraint_Error is
raised if the runtime is compiled with checks on, otherwise a memory
corruption occurs. Use the constant NI_MAXHOST to ensure that the
appropriate buffer size is allocated for the hostnames.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/g-socket.ads (Max_Name_Length): Initialize with
NI_MAXHOST.
diff --git a/gcc/ada/libgnat/g-socket.ads b/gcc/ada/libgnat/g-socket.ads
--- a/gcc/ada/libgnat/g-socket.ads
+++ b/gcc/ada/libgnat/g-socket.ads
@@ -1558,8 +1558,10 @@ private
No_Sock_Addr : constant Sock_Addr_Type := (Family_Inet, No_Inet_Addr, 0);
- Max_Name_Length : constant := 64;
- -- The constant MAXHOSTNAMELEN is usually set to 64
+ Max_Name_Length : constant := SOSC.NI_MAXHOST;
+ -- Most systems don't provide constants that specify the maximum size
+ -- of either a FQDN or a service name. In order to aid applications in
+ -- allocating buffers, the constant NI_MAXHOST is defined in <netdb.h>.
subtype Name_Index is Natural range 1 .. Max_Name_Length;