Home > Back-end >  Why the program is running will collapse,, the great god
Why the program is running will collapse,, the great god

Time:10-04

Part of the following program code for me, and I don't know will collapse in the test and operation, and for which great god answers,

The sendmail. H file
 # pragma once 
#include
using namespace std;
Struct SMailInfo//email information
{
Char * m_UserName;
Char * m_UserPassWord;
STD: : string m_SenderName;
Char * m_Sender;
STD: : vector M_vReceiversAddress;
Char * m_Title;
Char * m_Body;
Char * m_IPAddr;
Char * m_IPName;
SMailInfo () {memset (this, 0, sizeof (SMailInfo)); }
~ SMailInfo ()
{}
};

The class CSendMail
{
Public:
CSendMail (void) {m_FileBuff=NULL;
};
~ CSendMail (void) {if (NULL!=m_FileBuff)
Free (m_FileBuff);
M_FileBuff=NULL;
};

Public:
Bool SendMail (SMailInfo & amp; SmailInfo)
{
Memcpy (& amp; M_sMailInfo, & amp; SmailInfo, sizeof (smailInfo));
If (m_sMailInfo m_Body==NULL
. | | m_sMailInfo m_IPAddr==NULL
. | | m_sMailInfo m_IPName==NULL
| | m_sMailInfo. M_vReceiversAddress. Empty ()
. | | m_sMailInfo m_Sender==NULL
. | | m_sMailInfo m_Title==NULL
. | | m_sMailInfo m_UserName==NULL
. | | m_sMailInfo m_UserPassWord==NULL)
{
return false;
}
The SOCKET sock;

return true;
}

Protected:

STD: : vector M_pcFilePath;
Char m_SendBuff [4096].//send buffer
Char m_ReceiveBuff [1024].
Char * m_FileBuff;//points to the attachment content
SMailInfo m_sMailInfo;
};


Main. CPP file
 # include 
#include
#include
#include
#include
# include "sendmail. H"
using namespace std;

Void main ()
{
SMailInfo mailInfo;
MailInfo. M_UserName="[email protected]";
MailInfo. M_UserPassWord="123";
MailInfo. M_Sender="[email protected]";

MailInfo. M_vReceiversAddress. Push_back (STD: : string (" [email protected] "));

MailInfo. M_Title="crash file";
MailInfo. M_Body="fast loading collapse file";
MailInfo. M_IPAddr="";
MailInfo. M_IPName="Mail. Appfactory. Cn";
//
//
CSendMail smtpMail;
Bool bsuccess=smtpMail. SendMail (mailInfo);
return ;

}



To debug the crash when positioning to the void xmemory deallocate (pointer _Ptr, size_type)
{//deallocate object at _Ptr, ignore the size
: : operator delete (_Ptr);
}
Position, the vector is the reason??

CodePudding user response:

Your structure inside the pointer is not allocate space? You can use character array or use new or malloc allocation space before use!

CodePudding user response:

SMailInfo () {memset (this, 0, sizeof (SMailInfo)); }

There is a string member variables, cannot use memset function for this object

CodePudding user response:

You are defined in this structure character pointer, but your code don't see where the allocated memory is direct assignment, not AV to blame,
  • Related