__INTERNAL_fmt: Improve %check_formatted_len for arrays, check and insert '(null) byte per byte (instead of byte,qword,byte)

This commit is contained in:
2025-08-01 11:11:37 +02:00
parent 486b4d5d9b
commit 77c578e79b
2 changed files with 50 additions and 25 deletions

View File

@@ -194,10 +194,12 @@ __INTERNAL_fmt:
jmp .insertString
%endmacro
%macro check_formatted_len 2 ;check_format_len [return_label] [offset]
%macro check_formatted_len 2 ;check_format_len [return_label] [length offset]
test rbx, rbx
jz %%checkBufferLen
cmp r11, rbx
mov rax, r11
add rax, %2
cmp rax, rbx
jae .wrapup
jmp .flushReturn_%1
%%checkBufferLen:
@@ -260,6 +262,7 @@ __INTERNAL_fmt:
cmp byte [rdi], EOS
je .wrapup
check_formatted_len 0,1
;.flushReturn_0:
cmp byte [rdi], '\'
je .asciiReplacement
cmp byte [rdi], '%'
@@ -286,6 +289,7 @@ __INTERNAL_fmt:
jmp .invalidReplacement
.replaceAscii:
check_formatted_len 1, 1
;.flushReturn_1:
write_format_data byte,r10,r8b
add rdi, 2
inc r10
@@ -443,18 +447,43 @@ __INTERNAL_fmt:
.insertString:
test rsi, rsi
jnz .doInsertString
check_formatted_len 2, 7
check_formatted_len 2, 1
;.flushReturn_2:
write_format_data byte,r10,'('
write_format_data qword,r10+1,'null'
write_format_data byte,r10+5,')'
add r10, 6
add r11, 6
inc r10
inc r11
check_formatted_len 21, 1
;.flushReturn_21:
write_format_data byte,r10,'n'
inc r10
inc r11
check_formatted_len 22, 1
;.flushReturn_22:
write_format_data byte,r10,'u'
inc r10
inc r11
check_formatted_len 23, 1
;.flushReturn_23:
write_format_data byte,r10,'l'
inc r10
inc r11
check_formatted_len 24, 1
;.flushReturn_24:
write_format_data byte,r10,'l'
inc r10
inc r11
check_formatted_len 25, 1
;.flushReturn_25:
write_format_data byte,r10,')'
inc r10
inc r11
jmp .endInsertString
.doInsertString:
cmp byte [rsi], EOS
je .endInsertString
check_formatted_len 3, 1
;.flushReturn_3:
mov r8b, byte [rsi]
write_format_data byte,r10,r8b
inc rsi
@@ -512,13 +541,23 @@ __INTERNAL_fmt:
xor r10, r10
.flush_ret:
cmp r9b, 0
je .flushReturn_0
je .flushReturn_0 ;.process
cmp r9b, 1
je .flushReturn_1
je .flushReturn_1 ;.replaceAscii
cmp r9b, 2
je .flushReturn_2
je .flushReturn_2 ;.insertString "(null)
cmp r9b, 21
je .flushReturn_21 ;...
cmp r9b, 22
je .flushReturn_22 ;...
cmp r9b, 23
je .flushReturn_23 ;...
cmp r9b, 24
je .flushReturn_24 ;...
cmp r9b, 25
je .flushReturn_25 ;...
cmp r9b, 3
je .flushReturn_3
je .flushReturn_3 ;.doInsertString
.wrapup:
test rbx, rbx

View File

@@ -422,11 +422,7 @@ section .rodata
addTest(fgetmod2, "fgetmod(statbuff2)")
fgetmodStr db "\t- File permissions of file '%s': %04o\n",EOS
fmt_str db "%s",EOS
section .bss
fmt_out resb 5
fmt_over resb 64
inputBuffer_4 resb 4
inputBuffer_32 resb 32
strBuff1 resb 64
@@ -1665,16 +1661,6 @@ _start:
sub rcx, r14
call printf
lea rdi, [rel fmt_out]
mov rsi, 5
lea rdx, [rel fmt_str]
xor rcx, rcx
call format
lea rdi, [rel fmt_out]
call puts
lea rdi, [rel fmt_over]
call puts
;--- exit()
xor rdi, rdi
call exit