News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Another mysterious

Started by Manos, December 17, 2013, 09:42:48 AM

Previous topic - Next topic

Manos

Hi All.

Because CoderStudio, (my IDE), support also C language,
yesterday I loaded a C file to check if this colorized correctly.
The name was Demo.c.
But to my surprise, when I close the file, only when close, the program craches.
I open a file named Demo.h and the problem was the same.
Two days I try to find the error. I searched the source to find some invalid pointer, but nothing.
When I open the file Demo.asm or Demo.inc or Demo.rc, no problem.
I thinked that the .c and .h extensions are the problem. I thinked why ?
I open a file without extension named Demo and it works OK.
I open a file with another extension, like Demo.a and the problem appears again.
Finally  I discovered that the problem is not in extension but in the total number characters of
the file title including the extension.
That is, if the number of characters of file title are 6, the program craches.
If I open a file named Demo.c or Demo.h or De.asm, the program craches.
If I rename the file from Demo.c to Demoooooo.c no problem.
The program craches only if the file title including its extension has 6 characters.
I use crt dynamically, that is, the msvcrt.dll.
I don't know what happen.
Is this a problem of msvcrt ?

Manos.

qWord

Where does the debugger breaks? What does the stack trace tell you?
How should we help you without any code?
MREAL macros - when you need floating point arithmetic while assembling!

Manos

Hi qWord.

I open VS6.0 debuger but VS6.0 craches.
I open Ollydbg and it points me an access violation in MSVCRT.
Finally I found the error.
For each MDIChild window I allocate memory for private data, like file path, file title e.t.c.
Also I allocate memory for file title when the document is changed and not saved,
that is, the same file title with an asterisk more.
So, if the title is Demo.c, the marked title is Demo.c* when the document is changed.
Have a look follow:
Demo.c = 6 characters + 1 for null terminator = 7 characters.
When allocate memory for 7 characters, CRT gives me 8 bytes because CRT memory granularity is 8 bytes and the program works OK.
Demo.c* = 7 characters + 1 for null terminator = 8 characters. That is OK.
But later I added a space character between .c and * that is, the Demo.c* becames Demo.c * for better appearance.
Demo.c* = 7 characters + 1 for null terminator = 8 bytes.
Demo.c *  = 7 characters + 1 for space + 1 for null terminator = 9 bytes.
But I forgot to allocate 1 byte more for the space character and therefore the program craches.
The problem does not appears in Demo.asm because CRT memory granularity is 8 bytes.
Have a look follow:
Demo.asm* = 9 characters + 1 for null terminator = 10 bytes. CRT gives 16 bytes. OK.
Demo.asm * =  9 characters + 1 for space + 1 for null terminator = 11 bytes. CRT gives 16 bytes.
Because of my error, I requested 10 bytes instead of 11, but because CRT gives 16 bytes, no problem.
This is why the program craches in Demo.c and not in Demo.asm.

Manos.