The following code

bool endsWith(string str, string end)
{
        size_t to = str.length - end.length;
        for(sizediff_t i = str.length - 1; i >= to; --i)
        {
                if(str[i] != end[i-to])
                        return false;
        }
        return true;
}

int main(string[] args)
{
        return cast(int)endsWith("blub", "blub");
}

compiled with dmd 2.060 gives me a range violation. (with i = -1) although it shouldn't. If I change to from size_t "to" sizediff_t everything is fine. The comparison between the unsigned "to" and the signed "i" is not done correctly.

Is this a code gen bug? Or is it missing a compiler warning / error? Or is this entierly my fault?

Kind Regards
Benjamin Thaut

Reply via email to