===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 1998-2012, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -1004,7 +1004,7 @@
is
Length : constant File_Offset := File_Offset (File_Length (FD));
-- Include room for EOF char
- Buffer : constant String_Access := new String (1 .. Length + 1);
+ Buffer : String_Access := new String (1 .. Length + 1);
This_Read : Integer;
Read_Ptr : File_Offset := 1;
@@ -1020,9 +1020,16 @@
end loop;
Buffer (Read_Ptr) := EOF;
- Contents := new String (1 .. Read_Ptr);
- Contents.all := Buffer (1 .. Read_Ptr);
+ if Read_Ptr = Length then
+ Contents := Buffer;
+
+ else
+ Contents := new String (1 .. Read_Ptr);
+ Contents.all := Buffer (1 .. Read_Ptr);
+ Free (Buffer);
+ end if;
+
-- Things aren't simple on VMS due to the plethora of file types and
-- organizations. It seems clear that there shouldn't be more bytes
-- read than are contained in the file though.