Bug 9753 – std.string.translate precondition asserts

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-18T15:11:00Z
Last change time
2013-03-19T11:15:51Z
Keywords
pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-03-18T15:11:02Z
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);
Comment #1 by andrej.mitrovich — 2013-03-18T15:13:58Z
Why are those asserts in there anyway? A char can't be larger than 255..?
Comment #2 by bearophile_hugs — 2013-03-18T15:36:03Z
(In reply to comment #1) > 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); }
Comment #3 by andrej.mitrovich — 2013-03-18T15:46:49Z
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.
Comment #4 by github-bugzilla — 2013-03-18T17:51:13Z
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 Merge pull request #1211 from AndrejMitrovic/Fix9753 Issue 9753 - Remove unnecessary asserts.