The following segfaults when compiled with DMDv2.071.1 (x86 and x86_64, no flag):
void main() {
ubyte[] buf;
buf.length = -1;
}
Here is the relevant GDB backtrace:
#0 0xb7c1708a in __memset_sse2_rep () from /usr/lib/libc.so.6
#1 0x080f51d6 in _d_arraysetlengthT ()
While I do not argue that setting a negative length is meaningless an Error should be thrown instead of segfaulting.
This was found while fuzzing arsd/png.d with afl (American Fuzzy Loop).
Comment #1 by ag0aep6g — 2016-09-05T21:16:51Z
There's no such thing as a negative length. -1 becomes size_t.max. Still shouldn't segfault, though. Should throw an OutOfMemoryError.
Comment #2 by lodovico — 2016-09-06T12:30:30Z
*** Issue 16469 has been marked as a duplicate of this issue. ***
Comment #3 by bitter.taste — 2017-01-11T14:13:59Z
This is caused by not-so-wise decision to to allow the implicit conversion from {int,long} to u{int,long} (but not for {byte,short} to u{byte,short}, go figure) so even though it is possible to catch this error at compile time a blind eye is turned instead.