www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17650] New: [REG v2.075.0 b1-b4] std.getopt range violation

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

          Issue ID: 17650
           Summary: [REG v2.075.0 b1-b4] std.getopt range violation
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jrdemail2000-dlang yahoo.com

The unit test below passes in 2.074.1 but fails in 2.075.0 beta-1 and beta-4

===== getopt_test.d =====
import std.getopt;

unittest // Dashes
{
    auto args = ["program", "-m", "-5", "-n", "-50", "-c", "-"];

    int m;
    int n;
    char c;

    getopt(
        args,
        "m|mm", "integer", &m,
        "n|nn", "integer", &n,
        "c|cc", "character", &c,
        );

    assert(m == -5);
    assert(n == -50);
    assert(c == '-');
}

(The above adopted from tsv utilities unit tests here:
https://github.com/eBay/tsv-utils-dlang/blob/master/common/src/getopt_inorder.d#L302)

With 2.074.1 (succeeds):

$ ./dmd2.074.1  --version
DMD64 D Compiler v2.074.1
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

$ ./dmd2.074.1  -unittest -main -run getopt_test.d
$

With 2.075.0 beta-4 (error):

$ dmd --version
DMD64 D Compiler v2.075.0-b4
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

$ dmd -unittest -main -run getopt_test.d
core.exception.RangeError std/getopt.d(1112): Range violation
----------------
4   dmd_runceaLDU                       0x000000010f02a06a _d_arrayboundsp +
110
5   dmd_runceaLDU                       0x000000010f046f03  safe bool
std.getopt.optMatch(immutable(char)[], immutable(char)[], ref
immutable(char)[], std.getopt.configuration) + 639
6   dmd_runceaLDU                       0x000000010f01558d  safe bool
std.getopt.handleOption!(int*).handleOption(immutable(char)[], int*, ref
immutable(char)[][], ref std.getopt.configuration, bool) + 985
7   dmd_runceaLDU                       0x000000010f014a88  safe void
std.getopt.getoptImpl!(immutable(char)[], immutable(char)[], int*,
immutable(char)[], immutable(char)[], int*, immutable(char)[],
immutable(char)[], char*).getoptImpl(ref immutable(char)[][], ref
std.getopt.configuration, ref std.getopt.GetoptResult, ref
std.getopt.GetOptException, void[][immutable(char)[]],
void[][immutable(char)[]], immutable(char)[], immutable(char)[], int*,
immutable(char)[], immutable(char)[], int*, immutable(char)[],
immutable(char)[], char*) + 1164
8   dmd_runceaLDU                       0x000000010f014349  safe
std.getopt.GetoptResult std.getopt.getopt!(immutable(char)[],
immutable(char)[], int*, immutable(char)[], immutable(char)[], int*,
immutable(char)[], immutable(char)[], char*).getopt(ref immutable(char)[][],
immutable(char)[], immutable(char)[], int*, immutable(char)[],
immutable(char)[], int*, immutable(char)[], immutable(char)[], char*) + 189
9   dmd_runceaLDU                       0x000000010f011961 void
getopt_test.__unittestL3_1() + 301
10  dmd_runceaLDU                       0x000000010f011808 void
getopt_test.__modtest() + 8
11  dmd_runceaLDU                       0x000000010f02a8d0 int
core.runtime.runModuleUnitTests().__foreachbody2(object.ModuleInfo*) + 44
12  dmd_runceaLDU                       0x000000010f02096e int
object.ModuleInfo.opApply(scope int
delegate(object.ModuleInfo*)).__lambda2(immutable(object.ModuleInfo*)) + 34
13  dmd_runceaLDU                       0x000000010f042205 int
rt.minfo.moduleinfos_apply(scope int
delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref
rt.sections_osx_x86_64.SectionGroup) + 85
14  dmd_runceaLDU                       0x000000010f042190 int
rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))) +
32
15  dmd_runceaLDU                       0x000000010f020945 int
object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) + 33
16  dmd_runceaLDU                       0x000000010f02a7ba runModuleUnitTests +
126
17  dmd_runceaLDU                       0x000000010f03a9aa void
rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
+ 22
18  dmd_runceaLDU                       0x000000010f03a943 void
rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) + 31
19  dmd_runceaLDU                       0x000000010f03a8ae _d_run_main + 458
20  dmd_runceaLDU                       0x000000010f01182f main + 15
21  libdyld.dylib                       0x00007fffc7550234 start + 0
22  ???                                 0x0000000000000000 0x0 + 0

--
Jul 14 2017