fix issue 18300: range error demangling long symbol #2062
Conversation
That was quick. Almost like you have seen it coming ;-). Thanks for the fix. |
@rainers It would be great if you could add a test for it. D is trying to get more and more stable and every bug fixed shouldn't appear again. Thanks! |
Adding the symbol from the test case to the unittests in core.demangle would increase the file size by about 30k, probably with a measurable impact on every import of core.demangle. |
Oh, I thought that's already the case. |
I added a unittest that triggers the problem with small symbols, too, by passing a small initial buffer (first range error with buffer size 4). |
auto ds = demangle(s, buf); | ||
assert(ds == "pure nothrow @safe char[] core.demangle.demangle(const(char)[], char[])"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: added as unittest below
changed commit message to also reference https://issues.dlang.org/show_bug.cgi?id=18208, as 18300 turnedout to be a duplicate. |
|
This PR also contains a test for a small symbol for a variety of initial buffer length.
Sounds good, especially in the case of the other "remove" bug. In issue 18300 the limit has to be hit exactly, which does not seem very probable to begin with (there are thousands of large symbols in the phobos unittests but none triggered the error). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I added the unittest without changing the buffer size below and I think this rested in the PR queue way too long
In the interest of getting this in before 2.079, I rebased to |
The range error occurs if the demangler happens to hit the length of the buffer (which is a multiple of 4000 by default) with the chunk it tries to write into the buffer.
I didn't add the test case to the unittests because it's a 17k string which seems excessive.