# Bug in GNAT Ada.Text\_IO.Get\_Line

**URL:** https://forum.ada-lang.io/t/bug-in-gnat-ada-text-io-get-line/1779
**Category:** General
**Tags:** gnat, bug, text\_io
**Created:** [February 5, 2025, 6:10pm UTC](https://forum.ada-lang.io/t/bug-in-gnat-ada-text-io-get-line/1779 "2025-02-05T18:10:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![krischik](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/krischik/32/420_2.png) [@krischik](https://forum.ada-lang.io/u/krischik)
#### Post date: [February 5, 2025, 6:10pm UTC](https://forum.ada-lang.io/t/bug-in-gnat-ada-text-io-get-line/1779/1 "2025-02-05T18:10:07Z")

</div>

About 20 years ago I noted a bug in `Ada.Text_IO.Get_Line`. The bug affects files where the LF is missing on the last line **and** the length of last line is multiple of the internal buffer length. Very obscure.

Back then I wrote a workaround but today I noted that it’s not needed as AdaCore has fixed the bug. 🎉 — Only, AdaCore did not fix the bug in `Ada.Wide_Text_IO.Get_Line` and `Ada.Wide_Wide_Text_IO.Get_Line`. 😣.

You can see the bug in the source code. Im [Ada.Text\_IO](https://github.com/gcc-mirror/gcc/blob/50a31b6765fe17aee22a1fc1457c762a53140c8e/gcc/ada/libgnat/a-textio.adb#L752) line 752 you can see the check for `End_Of_File` while in [Ada.Wide\_Text\_IO](https://github.com/gcc-mirror/gcc/blob/50a31b6765fe17aee22a1fc1457c762a53140c8e/gcc/ada/libgnat/a-witeio.adb#L739) the check for `End_Of_File` is missing.

And worse of all: my workaround is not working any more because `Get_Line` will now try to read arbitrary long lines.

---

<div class="post-metadata">

### Author: ![krischik](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/krischik/32/420_2.png) [@krischik](https://forum.ada-lang.io/u/krischik)
#### Post date: [February 5, 2025, 6:56pm UTC](https://forum.ada-lang.io/t/bug-in-gnat-ada-text-io-get-line/1779/2 "2025-02-05T18:56:47Z")

</div>

I have corrected version of `Get_Line` in [AdaCL.Wide\_Strings.IO](https://sourceforge.net/p/adacl/git/ci/d434c7f0fc786f780b76673cf84ae1bd0ca56445/tree/adacl/src/adacl-wide_strings-io.adb) and [AdaCL.Wide\_Wide\_Strings.IO](https://sourceforge.net/p/adacl/git/ci/d434c7f0fc786f780b76673cf84ae1bd0ca56445/tree/adacl/src/adacl-wide_wide_strings-io.adb).

There are alse unit test in [AdaCL.Wide\_Strings.IO.Test](https://sourceforge.net/p/adacl/git/ci/d434c7f0fc786f780b76673cf84ae1bd0ca56445/tree/adacl/test/src/adacl-wide_strings-io-test.adb) and [AdaCL.Wide\_Wide\_Strings.IO.Test](https://sourceforge.net/p/adacl/git/ci/d434c7f0fc786f780b76673cf84ae1bd0ca56445/tree/adacl/test/src/adacl-wide_wide_strings-io-test.adb) so I know it actually works.
