[Issue 24557] File.readln does not properly handle case where last character in terminator is repeated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 20 17:38:51 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24557

Steven Schveighoffer <schveiguy at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at gmail.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from Steven Schveighoffer <schveiguy at gmail.com> ---
readln does use the last character, but it is also validating the "line" ends
in the full termination sequence.

However, the bug is that if the last character is repeated in the termination
sequence, it checks just the new data that it has read for the termination
sequence.

So for example, if you look for `ging` as the termination sequence, the
following algorithm results (assume input is `bringing home the bacon`):

1. result = "", readln('g') => "bring". Does "bring" end in "ging"? no
2. result = "bring", readln('g') => "ing". Does "ing" end in "ging"? no
3. result = "bringing", readln('g') => " home the bacon". readln returned no
delim found, so result is "bringing home the bacon"

Instead, readln should check the *concatenated* result (but obviously, only the
result that has been appended since the readln call was started.

--


More information about the Digitalmars-d-bugs mailing list