Thread overview | |||||
---|---|---|---|---|---|
|
March 31, 2006 Bug in string or AA handling | ||||
---|---|---|---|---|
| ||||
This code segfaults on linux with dmd 0.150 even with all debug-flags on: import std.string, std.date, std.random; alias char[] String; class Node { String label; Node[char] successors; this(String l) { label = l; } void countCommonPrefix(String str) { int a = str.length, b = label.length, m = a < b ? a : b, c; while (c < m && str[c] == label[c]) c++; } void add(String str) { if (!(str[0] in successors)) successors[str[0]] = new Node(str); successors[str[0]].countCommonPrefix(str); } } void main() { String data; for(int i=0; i<100; i++) data ~= lowercase[rand()%lowercase.length]; real estimate = getUTCtime() + TicksPerSecond*10; while (getUTCtime<estimate) { auto root = new Node("a"); for (int i = 0; i < data.length; ++i) root.add(data[i..$]); } } Any idea, why it does so? If you shorten the time interval or data string length, it may not segfault. This is a "minimal" test case made of the suffix tree algorithm I had previously problems with. Another way to prevent segfaults may (YMMV) be to use this "fix": row 11: - while (c < m && str[c] == label[c]) c++; + while (c < m) if (str[c]==label[c]) c++; I don't understand - &&-expressions should actually work this way. See http://www.digitalmars.com/d/expression.html#AndAndExpression. -- Jari-Matti |
March 31, 2006 Re: Bug in string or AA handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jari-Matti Mäkelä | Jari-Matti Mäkelä wrote:
> This code segfaults on linux with dmd 0.150 even with all debug-flags on:
>
> import std.string, std.date, std.random;
> alias char[] String;
>
> class Node {
> String label;
> Node[char] successors;
It does look like the AA problem with the key type not being a multiple size of a pointer size. A fix for this will go out in the next update.
|
March 31, 2006 Re: Bug in string or AA handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Jari-Matti Mäkelä wrote:
>> This code segfaults on linux with dmd 0.150 even with all debug-flags on:
>>
>> import std.string, std.date, std.random;
>> alias char[] String;
>>
>> class Node {
>> String label;
>> Node[char] successors;
>
> It does look like the AA problem with the key type not being a multiple size of a pointer size. A fix for this will go out in the next update.
Ok, thanks. I knew there was an AA thing already in the bugzilla, but you never can be too sure :)
|
Copyright © 1999-2021 by the D Language Foundation