Bug in string or AA handling
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Fri Mar 31 13:42:06 PST 2006
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
More information about the Digitalmars-d-bugs
mailing list