Comment #3 by dlang-bugzilla — 2017-07-15T05:30:51Z
Interesting - looking at the PR, this doesn't really seem like a regression, rather that the addition of the @safe attribute exposed an out-of-bounds array access that was always there. Feel free to reclassify, Jon.
Comment #4 by dlang-bugzilla — 2017-07-15T05:35:05Z
Actually, I believe we do count a breakage as a regression if something breaks for the end-user, regardless of what is going on under the hood. E.g. it's possible that for supported architectures, the range violation was completely benign.
Comment #5 by jrdemail2000-dlang — 2017-07-15T06:23:27Z
Wow. So I introduced this, initiated by trying add new unit tests. And my own unit tests caught it, but unfortunately, not the unit tests I added to Phobos. How ironic. Thanks for investigating Vladimir.
Comment #6 by petar.p.kirov — 2017-07-15T08:12:41Z
The error doesn't make sense to me. @safe adds bounds checks where there are none only when building with -release. I.e. if we're not building with -release, there shouldn't be any change in behavior - bounds checking should already be present (-boundscheck defaults to 'on' in that case). Am I missing something?
Comment #7 by jrdemail2000-dlang — 2017-07-15T15:31:06Z
(In reply to ZombineDev from comment #6)
> The error doesn't make sense to me. @safe adds bounds checks where there are
> none only when building with -release. I.e. if we're not building with
> -release, there shouldn't be any change in behavior - bounds checking should
> already be present (-boundscheck defaults to 'on' in that case). Am I
> missing something?
There was already an existing range violation, one that didn't have a unit test in the std.getopt module. Adding @safe to the function turned on bounds checking in debug mode. I had a unit test in my own code (not std.geopt) that triggered the out-of-bounds case. This unit test didn't get run until I actually ran my own unit tests with the new code.
The out-of-bounds case occurs when there is an command line argument that is a single dash. e.g.
$ myprogram -x a # okay
$ myprogram -x - # out-of-bounds
In the single dash case there's an attempt to access one character past it. Kind of understandable there wasn't a unit test for this originally. If you want to see the sequence that led to adding @safe read https://github.com/dlang/phobos/pull/5347.
Comment #8 by jrdemail2000-dlang — 2017-07-15T19:54:35Z
I'm preparing a PR to fix the underlying issue. A concern for the general release is that a single hyphen is often used to represent standard input in command line args. e.g.
$ cat file.txt | my_d_program --file - > out.txt
This will trigger the bounds check error if my_d_program is compiled in safe mode.
Comment #9 by jrdemail2000-dlang — 2017-07-15T20:31:59Z