I have a proc in my app, that reads some stuff from the registry. The app works fine in my computer. But in my sister's computer it crashes.
I found out that the error was in that proc. When I put a MessageBox as the first "command" of the proc, the MessageBox doesn't appear (the program crashes before):

ReadRegistryVars proc
LOCAL hKey:DWORD
LOCAL Disp:DWORD
LOCAL strData[8193]:BYTE
LOCAL dwData:DWORD
LOCAL RegType:DWORD
LOCAL cbData:DWORD
invoke MessageBox, 0, addr SomeString, addr SomeString, 0
(...)

And when I put a MessageBox before the call to the proc like this:
invoke MessageBox, 0, addr SomeString, addr SomeString, 0
invoke ReadRegistryVars
Then the MessageBox appears and the program crashes right after.
I figure out the problem was the LOCAL variables and it was!
When I moved the variables to the ".data?" section, the program worked fine in my PC and in my sister's PC.
I can't understand why my program worked fine on my PC (PII 300, 128RAM, WinME) and in my sister's PC (PII400, 64RAM, Win98) I had to change the LOCAL variables to the ".data?" section to make it work.
Does anyone know why this happened?
I had trouble with LOCAL variables before.
Is it a bad idea to use LOCAL variables?

Thanks in advance.
Posted on 2001-12-20 12:12:14 by dilau
Your trying to grab too much of the stack space at once. You can fix it with just touching the stack at 4K intervals. There is a thread somewhere here on this. Try this for the above case:
mov eax,[ebp - 4096]

invoke MessageBox,...
Does this work?

For each 4K over 4K you need to touch the stack at 4K interval before using the stack. For example if you wanted to grab 32K of the stack, you would do:
BigStackHog PROC huh:DWORD, what:DWORD

LOCAL BigStuff[08000h]:BYTE

mov eax,[ebp - 01000h] ; "touch" stack...
mov eax,[ebp - 02000h]
mov eax,[ebp - 03000h]
mov eax,[ebp - 04000h]
mov eax,[ebp - 05000h]
mov eax,[ebp - 06000h]
mov eax,[ebp - 07000h]

(...do your stuff here...)

ret
BigStackHog ENDP
Posted on 2001-12-20 13:08:51 by bitRAKE
Or use GlobalAlloc to allocate memory for strData variable.

Sami
Posted on 2001-12-20 13:23:31 by SamiP
Thanks guys! :)
I have some questions about this...
Why the program worked on my PC and didn't wotk in my sister's PC?
Is it unsafe to use LOCAL variables? I mean, how can I how many bytes I can use (LOCAL variable:BYTE)? What's the limit? 4096 bytes?
What's the safest method? GlobalAlloc or touching the stack?
Thanks in advance.
Posted on 2001-12-21 11:19:35 by dilau
The 'safe' size depends on the OS - I assume 4096.
Touching the stack is kind of the wrong method, but
it works. Better to use GlobalAlloc.
Posted on 2001-12-21 17:27:04 by bitRAKE
The reason that the app crashed on your sisters computer and not yours was probably because once the stack has been 'touched' it remains visible and acessible in memory.

So when run on your computer the strData was probably already on acessible memory so it didn't cause the page fault.
Posted on 2001-12-21 18:29:30 by huh
Thanks again, guys! :)
Posted on 2001-12-22 10:29:24 by dilau
On the subject, you can actualy direct masm to use your own user defined macros to defind local varibles (Pre/Epi) if u bother to design them yourself.
Posted on 2001-12-22 18:08:45 by huh
Posted on 2001-12-22 20:43:51 by bitRAKE