[Ada] Implement AI 242

Arnaud Charlet charlet@adacore.com
Mon Jan 3 16:11:00 GMT 2005


Tested on x86-linux, committed on mainline.

In the Ada RM for Ada 95 (RM B.3.1(49)) there is a statement that a call
to Update with a string parameter is equivalent to the effect of the call
Update(Item, Offset, To_C (Str), Check). But as pointed out in the AI-242
discussion (www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00242.TXT?rev=1.6),
this is a clear error with the unintended consequence of truncating the
string after the point of the update. AI-242 specifies the appropriate
correction Update(Item, Offset, To_C (Str, Append_Nul => False), Check).
Since this a correction of a clear error, it seems appropriate to apply
the correction unconditionally, so that it applies in Ada 95 mode as
well. It seems unlikely that any program would be relying on this bug.

2005-01-03  Robert Dewar  <dewar@adacore.com>

	* i-cstrin.adb (Update): Do not append a null in form called with a
	String. This avoids unintended behavior.

-------------- next part --------------
Index: i-cstrin.adb
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/i-cstrin.adb,v
retrieving revision 1.7
diff -u -p -r1.7 i-cstrin.adb
--- i-cstrin.adb	5 Mar 2004 10:58:56 -0000	1.7
+++ i-cstrin.adb	3 Jan 2005 15:15:09 -0000
@@ -250,7 +250,13 @@ package body Interfaces.C.Strings is
       Check  : Boolean := True)
    is
    begin
-      Update (Item, Offset, To_C (Str), Check);
+      --  Note: in RM 95, the Append_Nul => False parameter is omitted. But
+      --  this has the unintended consequence of truncating the string after
+      --  an update. As discussed in Ada 2005 AI-242, this was unintended,
+      --  and should be corrected. Since this is a clear error, it seems
+      --  appropriate to apply the correction in Ada 95 mode as well.
+
+      Update (Item, Offset, To_C (Str, Append_Nul => False), Check);
    end Update;
 
    -----------


More information about the Gcc-patches mailing list