Re: Program crashes before it starts!!!
- From: "Scherbina Vladimir" <vladimir.scherbina@xxxxxxxxxxxx>
- Date: Fri, 7 Jul 2006 15:08:02 +0300
See comments inline.
"JC" <jeffreycameron@xxxxxxxxx> wrote in message
news:1152269916.128408.114360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
In response to your answers :
we basically use whatever Visual C++ puts in the DllMain function,
nothing fancy. I thought maybe one of the functions that composes the
DLL could have been the source of the problem.
Try to put the simplest code to dll:
.... DllMain(..)
{
return TRUE;
}
Both are using the Multi-Threaded Debug versions of the CRT (for debug)
and Multi-Threaded Release versions for Release.
We are using Visual Studio .NET 2003.
Another weird thing is that earlier, this error with
_CrtIsValidHeapPointer was occurring only when we called a function
that was inside the DLL. I thought this was perhaps because of some
string (char*) variables we pass to the DLL function being malloc'd
poorly so I switched to using arrays instead like this :
#define BUFFER_LENGTH 8192 /* its an 8k buffer, VERY large, the string
is not close to this size*/
It's very bad technique to allocate in stack huge arrays. In your case you
allocate it in the entry point so depending on the size of your stack
(default is 1 MB) it may cause stack overflow.
(in DLL)
int mydllfunc(char *string);
(before - crashing at function call)
int main(int argc, char *argv[])
{
char *mystr = NULL;
mystr = calloc(BUFFER_LENGTH, sizeof(char));
strcpy(mystr, argv[1]);
mydllfunc(mystr);
}
I would try to make sure that argv[1] is not longer then mystr. At least,
this line:
strcpy(mystr, argv[1]);
Is potential candidate for buffer overflows. Use StrCpyN instead.
(after - crashing on startup at first variable initialisation)
int main(int argc, char *argv[])
{
char mystr[BUFFER_LENGTH] = "";
strcpy(mystr, argv[1]);
mydllfunc(mystr);
}
This code is obviously simplified a bit but represents the problem.
Help!! :-)
Play with size of buffer. Does simple: char mystr[10]; causes the same
problem?
--
Vladimir
.
- References:
- Program crashes before it starts!!!
- From: JC
- Re: Program crashes before it starts!!!
- From: Ara Avanesyan
- Re: Program crashes before it starts!!!
- From: JC
- Program crashes before it starts!!!
- Prev by Date: Re: Program crashes before it starts!!!
- Next by Date: Re: Program crashes before it starts!!!
- Previous by thread: Re: Program crashes before it starts!!!
- Next by thread: Re: Program crashes before it starts!!!
- Index(es):
Relevant Pages
|