Commit 79abd78a authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

real fix for string_slice

parent 3721aaf8
...@@ -234,17 +234,21 @@ void __string_slice(int dst_idx) ...@@ -234,17 +234,21 @@ void __string_slice(int dst_idx)
Thunk* idx2 = arg(1); Thunk* idx2 = arg(1);
char* chars; char* chars;
int full_length;
if(str->desc == (Desc*) __STRING_PTR__) if(str->desc == (Desc*) __STRING_PTR__)
{ {
chars = str->_string_ptr->chars; chars = str->_string_ptr->chars;
full_length = str->_string_ptr->length;
} }
else else
{ {
chars = str->_array._chars; chars = str->_array._chars;
full_length = str->_array.length;
} }
int length = idx2->_int - idx1->_int; int length = idx2->_int - idx1->_int + 1;
if(idx1->_int + length > full_length) length = full_length - idx1->_int;
target = string_create(target, length); target = string_create(target, length);
memcpy(target->_array._chars, chars + idx1->_int, length); memcpy(target->_array._chars, chars + idx1->_int, length);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment