when I invoked StrLen or StdOut(which invokes StrLen), sometimes illegal read will happen, but this only happed in Win9x.

;in "StrLen"
push ebx
mov eax,item ; get pointer to string
lea edx, ; pointer+3 used in the end
mov ebx, ;<==error happens here.
Posted on 2003-04-20 21:43:25 by smallwaves

About the only problem I can see with Agner Fog's string length algo is that it will read up to 3 bytes past the end of a zero terminated string.

What you of course must watch is that the string is correctly zero terminated because if its not, the algo will read past the buffer end and give you a read fault protection error.

I have not seen any other problems with this algo but if you have a way to reproduce it, please post it here.


Posted on 2003-04-20 23:41:05 by hutch--
Error will not happen if I use Api "lstrlen" in netenum0.8(in netenum0.8.zip):

OutputResult proc lpStr1:dword
local dwTmp:dword,dLen:dword,hOutput:dword

invoke lstrlen,lpStr1
mov dLen,eax

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOutPut, eax

invoke WriteFile,hOutPut,lpStr1,dLen,ADDR dwTmp,NULL
invoke WriteFile,hList,lpStr1,dLen,addr dwTmp,NULL

OutputResult endp

in netneum1.0(in netenum.zip), I use StrLen and error happened.
Posted on 2003-04-21 06:59:02 by smallwaves
Error happened in Win9x when execute netenum1.0 like this(in netenum.zip)

d:\Project/Debug/netenum/n /g /c /d /s *.mp3 /a
Posted on 2003-04-21 07:02:11 by smallwaves
I think it is because lstrlen uses typical byte scanner while strlen scan dwords, thus it might access some inaccessible memory resulting in some GPF as what hutch had been saying...
Posted on 2003-04-21 07:19:10 by roticv

I downloaded your test program and can build it but I have no way of testing it. Will you try out this very simple byte scanner for me to see if it has any problems with the string data you are testing ?

slen proc src:DWORD

mov eax, src
dec eax
inc eax
cmp BYTE PTR [eax], 0
jne @B

sub eax, src


slen endp

This is a classic byte scanner that cannot fail if the string has a zero within the allocated buffer length.


Posted on 2003-04-21 09:01:53 by hutch--