www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6888] New: std.getopt.getopt: one-letter hash option causes range violation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6888

           Summary: std.getopt.getopt: one-letter hash option causes range
                    violation
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: maximzms gmail.com



PDT ---
The following code causes the error:
--------------------
import std.getopt;

void main()
{
    int[string] foo;
    auto args = ["", "-t", "a=1"];
    getopt(args, "t", &foo);
}
--------------------
core.exception.RangeError std.getopt(519): Range violation
--------------------

There is no error if bundling is turned on:
getopt(args, config.bundling, "t", &foo);

There is no error if the option contains more than one letter
e.g. "--tune"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 03 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6888




PDT ---
The bug is found!

In std/getopt.d:

If the option is not long and bundling is forbidden lines 587-588 are executed.
If arg looks like "-t" value is empty but !value is false, i.e. in the
following code all asserts are true:

test.d:
--------------------
void main()
{
    string s = "t";
    string s1 = s[1..$];
    string s2 = null;

    assert(s1 == null);
    assert(s2 == null);
    assert(!s1 == false); // Why?
    assert(!s2 == true);
}
--------------------

Hence in std/getopt.d in the line 464:
!val is false and val is empty when we come to line 519 and try to access its
contents.

I'm going to fix it right now.
But the behavior of empty slices looks like a bug of the compiler.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 03 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6888


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



https://github.com/D-Programming-Language/phobos/pull/315

https://github.com/D-Programming-Language/phobos/commit/0ee6a1afbd8686a8051af4c86df9333c22daec89

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 14 2011