News:

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

Possible bug in a2dw

Started by BinBeef, October 02, 2009, 11:43:14 PM

Previous topic - Next topic

BinBeef

Hi everyone! I have the following doubt, which I emailed to hutch [a t] movsd <dot> com long ago but I haven't got any response...
Here's the email's body:

"I was testing MASM32 v10 (from masm32v10r.zip) and found that the a2dw proc (m32lib\a2dw.asm) is not working properly...
In the following code:

a2dw proc uses ecx edi edx esi String:DWORD

     ;----------------------------------------
     ; Convert decimal string into dword value
     ; return value in eax
     ;----------------------------------------

     xor ecx, ecx
     mov edi, String
     invoke lstrlen, String

lstrlen modifies ecx (I checked it in the debugger), so when the main loop starts ecx != 0. Putting the "xor ecx, ecx" after the lstrlen call, solves the problem.
Is that right or am I missing something?
Thanks"

Cheers.

ecube

that'll clear ecx yes, but thats not the only problem with the alg, apparently it doesn't handle negative numbers right, which is a biggy. Here's some replace functions http://www.masm32.com/board/index.php?topic=11275.0

hutch--

Its an algo the Iczelion wrote over 10 years ago and it is dangerous code as ECX can be modified by an API call after it. It uses registers in non-standard ways preserving ECX and EDX which is not needed. Vaguely from memory he had tested it under win95 which at the time did not modify ECX but the algo needs a complete rewrite. I confess that I have never used it and its been about that long since I have seen it with the file date being 2000.

What I am not sure about is if Iczelion intended it to be for unsigned DWORD or for signed LONG values, if its for the former it should not handle negative numbers, if its for the latter it should handle plus and minus 2 gig like normal.

BinBeef,

If you saw the amount of junk mail I get regularly, you would understand why I miss the occasional email. The filtering is a lot better now, in the past I used to get between hundreds and thousands a day. Thanks for pointing out the problem, it will be replaced sooner or later with an algo that does work properly using the gp registers in a documented manner.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php