www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9753] New: std.string.translate precondition asserts

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

           Summary: std.string.translate precondition asserts
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



std.string.translate precondition contains code like this:


C[] translate(C = immutable char)(in char[] str, in char[] transTable, in
char[] toRemove = null)  trusted nothrow
    if(is(Unqual!C == char))
in
{
    assert(transTable.length == 256);
    foreach(char c; str)
        assert(c <= 256);
    foreach(char c; transTable)
        assert(c <= 256);
    foreach(char c; toRemove)
        assert(c <= 256);
}



I think those asserts should be:

assert(c < 256);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9753


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



15:13:58 PDT ---
Why are those asserts in there anyway? A char can't be larger than 255..?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9753





 Why are those asserts in there anyway? A char can't be larger than 255..?
Ah, right. My brain was switched too much off. This looks better: foreach (dchar c; str) assert(c < 256); But this is a full-range translate(), so it should work in the whole range of [0, 256[, so I this precondition: in { assert(transTable.length == 256); foreach(char c; str) assert(c <= 256); foreach(char c; transTable) assert(c <= 256); foreach(char c; toRemove) assert(c <= 256); } Should be: in { assert(transTable.length == 256); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9753


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



15:46:49 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1211

Btw, for these trivial things you might want to try making pull requests. We
can always use an extra hand with fixing things.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9753




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/c89bc4b0e3e09c550563e7a753647562ebd2f034
Fixes Issue 9753 - Remove unnecessary asserts.

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


Issue 9753 - Remove unnecessary asserts.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9753


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 19 2013