Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Apache DLL file - unexpected error - confused newbie

Reply
Thread Tools

Apache DLL file - unexpected error - confused newbie

 
 
Greg M
Guest
Posts: n/a
 
      05-24-2004
Hello, I am using Visual C++ Studio 6.0 to compile a module i have written
for apache under windows xp.
The code compiles perfectly, however when used by the dll, the code fails.
This causes my webdav client to fail..

Please could you help me by telling me what im doing wrong.

Greg Miell

FILE: fullrw.c

/*CUT*/

long dirs_size(const char *curdir)
{
struct _finddata_t c_file;
long hFile;
long totalsize=0;
char *curdirr;
char *filedir;
curdirr= (char*) curdir;
strcpy(curdirr, "\\*.*");

if( (hFile = _findfirst( curdirr, &c_file )) == -1L )
{}
else
{

if (c_file.attrib & _A_SUBDIR){

if ((strcmp(c_file.name,"."))==0) {
} else {
if ((strcmp(c_file.name,".."))==0) {
} else {
filedir = (char*) curdir;
strcpy(filedir,"\\");
strcpy(filedir,c_file.name);
totalsize += dirs_size(filedir);
//printf("Dir %d\n",totalsize);
}
}
}else{
totalsize += c_file.size;
//printf("Files %d\n",c_file.size);
};

while( _findnext( hFile, &c_file ) == 0 )
{

if (c_file.attrib & _A_SUBDIR){


if ((strcmp( c_file.name, "."))==0) {
} else {
if ((strcmp(c_file.name,".."))==0) {
} else {

if ((strcmp(c_file.name,".DAV"))==0) {
//printf("DAV");
} else {
filedir = (char*) curdir;
strcpy(filedir,"\\");
strcpy(filedir,c_file.name);
totalsize += dirs_size((const char*) filedir);
return 0;
}
//printf("Dir %d\n",totalsize);
}
}
}else{
totalsize += c_file.size;
//printf("Files %d\n",c_file.size);
};

}
_findclose( hFile );
}
return totalsize;
}

/*EOF*/


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-24-2004

"Greg M" <(E-Mail Removed)> wrote in message
news:40b1b484$0$20508$(E-Mail Removed)...
> Hello, I am using Visual C++ Studio 6.0 to compile a module i have written
> for apache under windows xp.
> The code compiles perfectly, however when used by the dll, the code fails.
> This causes my webdav client to fail..
>
> Please could you help me by telling me what im doing wrong.


Not using pointer correctly, see below.

>
> Greg Miell
>
> FILE: fullrw.c
>
> /*CUT*/
>
> long dirs_size(const char *curdir)
> {
> struct _finddata_t c_file;
> long hFile;
> long totalsize=0;
> char *curdirr;
> char *filedir;
> curdirr= (char*) curdir;
> strcpy(curdirr, "\\*.*");


curdirr is an initialised pointer, yet you are copying characters to
wherever it points to, this will crash your program.

>
> if( (hFile = _findfirst( curdirr, &c_file )) == -1L )


It there any reason you can't just say

if( (hFile = _findfirst( "\\*.*", &c_file )) == -1L )

Seems a lot easier.

> {}
> else
> {
>
> if (c_file.attrib & _A_SUBDIR){
>
> if ((strcmp(c_file.name,"."))==0) {
> } else {
> if ((strcmp(c_file.name,".."))==0) {
> } else {
> filedir = (char*) curdir;
> strcpy(filedir,"\\");
> strcpy(filedir,c_file.name);


Again filedir is an uninitialised pointer, or rather curdir is, but you've
make filedir and curdir point to the same garbage location. It's not enough
to declare a pointer you must also make it point somewhere.

Time for some revision on pointer usage I think. Or better still use C++
strings, You can use C++ strings pretty much like you are trying to use
pointers.

john


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-24-2004
>
> curdirr is an initialised pointer, yet you are copying characters to
> wherever it points to, this will crash your program.
>


Apologies, you've confused me with your variables called currdir and curdir,
if nothing else you should name your variables better.

You are also violating const correctness, which might be the cause of your
problem. Try getting some code to compile without using any char* casts.

You are also failing to check that you have enough room in curdir when you
copy characters to it, that's more likely to be the cause of your problems.

Best solution is to use C++ strings. You avoid all this pointer nonsense.

john


 
Reply With Quote
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      06-07-2004
[snips]

On Mon, 24 May 2004 09:38:26 +0100, Greg M wrote:

> long dirs_size(const char *curdir)
> {
> struct _finddata_t c_file;
> long hFile;
> long totalsize=0;
> char *curdirr;
> char *filedir;
> curdirr= (char*) curdir;
> strcpy(curdirr, "\\*.*");


No. No, no, no, no, no.

curdirr is now just an alias for curdir, which is explicitly defined by
the function header as being *non modifiable*. Which means calling code
can safely rely on the function *not* to attempt to do things like write
to it. Except you promptly do exactly that, in direct violation of the
promise made by the function header.

Either make the parameter modifiable and document exactly what the caller
needs to do (allocate 256 bytes, for example), or leave it as a const and
don't try to write to it.

Note that you have an explicit cast in there = (char *). As a general
rule of thumb, casts indicate you're doing something wrong. They do have
their uses, but if you find yourself needing to use one, you also need to
*really* be sure that using it is the Right Thing.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
starting apache with mod_perl, error on Apache.pm Selmar Perl Misc 2 07-21-2004 09:53 PM
Apache DLL file - unexpected error - confused newbie Correction Greg M C++ 0 05-24-2004 08:42 AM
mprapi.dll --> samlib.dll --> ntdll.dll issue. Some1 Computer Support 4 04-05-2004 02:02 AM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments