array.reverse segfaults
Tomas Lindquist Olsen
tomas at famolsen.dk
Wed Oct 22 04:10:20 PDT 2008
Tomas Lindquist Olsen wrote:
> Moritz Warning wrote:
>> Hi,
>>
>> This piece of code segfaults on Debian Linux (with dmd 1.035):
>> Can someone tell me why?
>>
>> char[] get(char[] str)
>> {
>> return new char[](4);
>> }
>>
>> void main(char[][] args)
>> {
>> char[] str = get("abc");
>> char[] reversed = str.reverse; // <-- access violation
>> }
>
> Simpler version:
>
> void main()
> {
> char[4] str;
> str.reverse;
> }
>
> Crashes in _adReverseChar when trying to memmove (3 - 255) bytes ;)
>
> My best guess is that is just doesn't handle char.init values properly!
When it tries to get the lower stride, it gets 0xFF from the table, but it doesn't check if
this value is usable.
Probably just ignoring these invalid bytes would make it work. But I think the real question
is, what should _adReverseChar really do on invalid UTF-8 input?
More information about the Digitalmars-d
mailing list