It seems there is a bug in the library of MASM32 :(. The rtrim function doesn't delete all right spaces from a string. For example:


INCLUDE \masm32\include\
INCLUDE \masm32\include\
INCLUDE \masm32\include\

INCLUDELIB \masm32\lib\kernel32.lib
INCLUDELIB \masm32\lib\masm32.lib


szTest DB "string    ", 0 ;10 symbols
szBuffer DB 30 dup(" "), 0


    invoke rtrim, ADDR szTest, ADDR szBuffer
    invoke lstrlen, ADDR szBuffer ; eax == 7, szBuffer == "string "
END main
You can watch it with a debugger. I corrected the rtrim function in this way:

    mov esi, source
    mov edi, dest
    rep movsb
    dec edi         ;<-- insert this line
    mov al, 0
    stosb           ; put terminator on string
Posted on 2001-04-18 03:37:00 by vkim
vkim, Thanks for finding this bug, something got lost with the last optimisation. The replacement procedure is below,

rtrim proc source:DWORD,dest:DWORD

    push esi
    push edi

    mov esi, source
    xor ecx, ecx        ; zero ecx to use as counter

    mov al, 
    inc esi
    inc ecx             ; get string length excluding zero
    cmp al, 0           ; exit loop on zero
    jne @B

    lea esi,     ; correct esi count

    mov al, 
    dec esi
    dec ecx
    cmp al, 32          ; loop if space
    je  @B
    cmp al, 9           ; loop if tab
    je @B

    cld                 ; read forward

    inc ecx
    mov esi, source
    mov edi, dest
    rep movsb

    mov , byte ptr 0

    pop edi
    pop esi


rtrim endp
Posted on 2001-04-18 04:35:00 by hutch--