News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Bug in StripLF function

Started by thomasantony, December 20, 2004, 08:34:26 AM

Previous topic - Next topic

thomasantony

Hi,
   The new forum software is cool, but my 399 POSTS arre gone :( . I found a big bug in the Striplf routine in the masm32 library. It gave me exceptions when I used it. I checked and found that it doesn't check for the end of a string. It went on reading after the end of the string. I I got a GPF. So I added an or al,al and je @F in the routine. I also changed it so that it removed not only ASCII 13 but also 10  since they usually come together.
The new routine is:

StripLF proc strng:DWORD

  ; -------------------------------
  ; scan through string, put ascii
  ; zero in place of ascii 13
  ; -------------------------------
    mov edx, strng
  @@:
    mov al, [edx]
    or al,al
    je @F
    inc edx
    cmp al, 13
    jne @B

    mov al, 0
    mov [edx-1], al
    mov [edx],al
    inc edx
  @@:
    ret

StripLF endp


Thomas Antony :alright:
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Jibz

Yes, it should definitely check for end of line .. the last inc edx in your code looks like it does no good.

hutch--

The StripLF proc was actually dedicated to the STDIN procedure which by spec terminates the buffer with 13,10,0 and it expects the leading ascii 13. It is easy enough to write a reliable general purpose procedure to do the job and it looks like Thomas has done so.

As usual, keep up the good work.  :U
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

thomasantony

Quote
Yes, it should definitely check for end of line .. the last inc edx in your code looks like it does no good.
Hi,
   You are right. The inc is not needed.  The other proc really pissed me off when it started crashing my programs for no apparent reason.

Thomas Antony :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free