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:

.386
.MODEL FLAT, STDCALL 
OPTION CASEMAP: NONE 

INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDE \masm32\include\masm32.inc

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

.DATA

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

.CODE

main:
    invoke rtrim, ADDR szTest, ADDR szBuffer
    invoke lstrlen, ADDR szBuffer ; eax == 7, szBuffer == "string "
    ret
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

    ret

rtrim endp
Regards, hutch@pbq.com.au
Posted on 2001-04-18 04:35:00 by hutch--