1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 10:37:58 +03:00

Fix bugs in string manipulation

Handling corner cases when string chunks
(Arrays) are full. This caused segfaults
if string lengths hit magic numbers.
This commit is contained in:
Ben Dudson 2017-11-21 12:00:25 +00:00
parent a69523e790
commit 12ab92c379
3 changed files with 20 additions and 14 deletions

View File

@ -1169,9 +1169,9 @@ core_concat:
ret
.missing_args:
; Return nil
; Return empty list
call alloc_cons
mov [rax], BYTE maltype_nil
mov [rax], BYTE maltype_empty_list
ret
.not_list:

View File

@ -265,8 +265,8 @@ pr_str:
.list_check_end:
; Check if this is the end of the list
mov cl, BYTE [r12 + Cons.typecdr]
cmp cl, content_nil
je .list_finished
cmp cl, content_pointer
jne .list_finished
; More left in the list
@ -344,18 +344,20 @@ pr_str:
je .map_check_end
; A value (nil, int etc. or function)
xor cl, container_map ; Remove map type -> value
mov BYTE [rsi], cl
xchg ch, cl
mov [rsi], BYTE cl ; Remove map type -> value
xchg ch, cl
push rcx
push r13
push r12
call pr_str ; String in rax
pop r12
pop r13
pop rcx
mov cl, BYTE [r12] ; Restore map type
mov cl, BYTE [r12]
or cl, container_map ; Restore map type
mov BYTE [r12], cl
jmp .map_loop_got_str
.map_loop_pointer:
mov rsi, [rsi + Cons.car] ; Address of object
@ -476,8 +478,8 @@ pr_str:
.vector_check_end:
; Check if this is the end of the vector
mov cl, BYTE [r12 + Cons.typecdr]
cmp cl, content_nil
je .vector_finished
cmp cl, content_pointer
jne .vector_finished
; More left in the vector

View File

@ -160,7 +160,7 @@ section .data
heap_cons_next: dd heap_cons_store ; Address of next cons in memory
heap_cons_free: dq 0 ; Address of start of free list
%define heap_array_limit 300 ; Number of array objects which can be created
%define heap_array_limit 1000 ; Number of array objects which can be created
heap_array_next: dd heap_array_store
heap_array_free: dq 0
@ -622,8 +622,8 @@ string_append_string:
mov r8d, DWORD [rbx + Array.length]
add r11, r8
cmp r8d, 0
je .return ; Appending zero-size array
test r8d, r8d
jz .return ; Appending zero-size array
; Find the end of the string in RSI
; and put the address of the Array object into rax
@ -646,6 +646,10 @@ string_append_string:
mov r9, rax
add r9, Array.size
; Check if we are at the end of the destination
cmp r8, r9
je .alloc_dest
.copy_loop:
; Copy one byte from source to destination
mov cl, BYTE [r10]