posts - 11,comments - 13,trackbacks - 0
定义一个vector:
typedef struct _SEED_TOP_
{
    std::
string m_Range;//192.168.1.1_192.168.1.255,192.168.2.1-192.168.2.255//每对起始结束ip之间用“,”分隔
    int            m_scansubnet;//true扫描子网,false不扫描子网,只扫描骨干网
    int            m_networkdevice;    //invalid
    int            m_server;            //invalid
    int            m_scanicmp;        //true表示需要拓扑开了icmp的设备,false不需要拓扑
    std::vector<std::string> m_snmpdevicelist;    //“startIp”,”endIp”,”community”,”retry”,”timeout”
    std::string                m_pingset;        //true,timeout,times //true设置ping,false不设置ping,这时就没有timeout和times参数,timeout表示超时单位为毫秒,times表示ping次数
    std::string                m_routerdevice;        //invalid
    int                        m_topologyalgorithm; //invalid

    _SEED_TOP_
&    operator = (_SEED_TOP_& value)
    
{
        m_Range 
= value.m_Range;
        m_scansubnet 
= value.m_scansubnet;
        m_server    
= value.m_server;
        m_scanicmp 
= value.m_scanicmp;

        
if(!m_snmpdevicelist.empty())
        
{
            m_snmpdevicelist.clear();
        }

        m_snmpdevicelist.assign(value.m_snmpdevicelist.begin(),value.m_snmpdevicelist.end());
        m_pingset    
= value.m_pingset;
        
return *this;
    }


    _SEED_TOP_(
const com::topology::SEEDTOP value)
    
{
        m_Range 
= value.mRange;
        m_scansubnet 
= value.mscansubnet;
        m_server    
= value.mserver;
        m_scanicmp 
= value.mscanicmp;

        
if(!m_snmpdevicelist.empty())
        
{
            m_snmpdevicelist.clear();
        }

        m_snmpdevicelist.assign(value.msnmpdevicelist.begin(),value.msnmpdevicelist.end());
        m_pingset    
= value.mpingset;
    }

    
    _SEED_TOP_()
    
{

    }

}
SEED_TOP;

typedef struct __THREAD_SEED__
{
    
int retry;
    
int timeout;
    std::
string seed;
    
int depth;
    std::vector
<std::string> community;

    std::vector
<IP_ADDR>    ip;
    
int scansubnet;
    
int icmp;
    std::vector
<SNMP_LIST_INFO> snmplist;
    PING_SET_INFO pinginfo;

    
int Init(void * data)
    
{

        SEED_TOP
* info = (SEED_TOP * )data;
        scansubnet 
= info->m_scansubnet;
        icmp    
= info->m_scanicmp;
        
//初始化起始IP
        std::string seperator;
        std::vector
<IP_ADDR> ipaddr;
        
while(memcmp((seperator = Get_Subvalue(info->m_Range,',')).c_str(),"_",1!= 0)
        
{
            std::
string startip;
            std::
string endip;
            IP_ADDR l_ip;
            startip 
= Get_Subvalue(seperator,'-');
            endip 
= Get_Subvalue(seperator,'-');
            l_ip.m_num 
= 2;
            memcpy(l_ip.m_ip,startip.c_str(),startip.size());
            l_ip.next 
= (IP_ADDR*)malloc(sizeof(IP_ADDR));
            
if(l_ip.next != NULL)
            
{
                memset(l_ip.next,
0,sizeof(IP_ADDR));
                memcpy(l_ip.next
->m_ip,endip.c_str(),endip.size());
            }

            
else
            
{
                
return -2;
            }

            std::
string tmp = startip;
            tmp 
+= '-';
            tmp 
+= endip;
            
/*if(ip.size()<=0)
            {
                ip.resize(10);
                ip.clear();
            }
            else if(ip.size() >= ip.capacity())
            {
                ip.resize(ip.capacity()*2);
            }
*/


            ip.push_back(l_ip);
            
if(memcmp(tmp.c_str(),info->m_Range.c_str(),info->m_Range.size()) == 0)
            
{
                
break;
            }

        }

        
        
//初始化snmp链表
        SNMP_LIST_INFO perinfo;
        memset((
char *)&perinfo,0,sizeof(SNMP_LIST_INFO));
        std::vector
<std::string> seedlist(info->m_snmpdevicelist.begin(),info->m_snmpdevicelist.end());
        std::vector
<std::string>::iterator list_iter = seedlist.begin();
        
for(;list_iter != seedlist.end();++list_iter)
        
{
            std::
string devicelist = (*list_iter);
            std::
string startip = Get_Subvalue(devicelist,',');
            std::
string endip = Get_Subvalue(devicelist,',');
            std::
string list_community = Get_Subvalue(devicelist,',');
            std::
string list_retry = Get_Subvalue(devicelist,',');
            std::
string list_timeout = Get_Subvalue(devicelist,',');
            
if((memcmp(startip.c_str(),"_",1== 0)||
                (memcmp(endip.c_str(),
"_",1== 0)||
                (memcmp(list_community.c_str(),
"_",1== 0)||
                (memcmp(list_retry.c_str(),
"_",1== 0)||
                (memcmp(list_timeout.c_str(),
"_",1== 0))
            
{
                
return -1;
            }

            perinfo.community 
= list_community;
            perinfo.retry 
= atol(list_retry.c_str());
            perinfo.timeout 
= atol(list_timeout.c_str());
            perinfo.ip.m_num 
= 2;
            memcpy(perinfo.ip.m_ip,startip.c_str(),startip.size());
            perinfo.ip.next 
= (IP_ADDR*)malloc(sizeof(IP_ADDR));
            
if(perinfo.ip.next == NULL)
            
{
                
return -2;
            }

            memset(perinfo.ip.next,
0,sizeof(IP_ADDR));
            memcpy(perinfo.ip.next
->m_ip,endip.c_str(),endip.size());
            perinfo.ip.next
->next = NULL;
            snmplist.push_back(perinfo);
        }


        
//初始化pingset结构
        std::string info_ping = info->m_pingset;
        std::
string sustain_icmp = Get_Subvalue(info_ping,',');
        std::
string c_timeout = Get_Subvalue(info_ping,',');
        std::
string c_retry = Get_Subvalue(info_ping,',');
        
if((memcmp(sustain_icmp.c_str(),"_",1== 0)||
            (memcmp(c_timeout.c_str(),
"_",1== 0)||
            (memcmp(c_retry.c_str(),
"_",1== 0))
        
{
            
return -3;
        }


        pinginfo.icmp 
= (memcmp(sustain_icmp.c_str(),"true",4== 0)?1:0;
        pinginfo.retry 
= atol(c_retry.c_str());
        pinginfo.timeout 
= atol(c_timeout.c_str());
        
return 0;
    }

}
THREAD_SEED;

THREAD_SEED seed.Init(&tmpinfo);

如果是release则在Init的ip.push_back(l_ip);行发生异常,但是debug版本就没有任何事,不知道是啥原因;
高手指导!!C 运行时错误
__declspec(noinline)
void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
    /* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
    (_Reserved);
    _debugger_hook_dummy = 0;
}
posted on 2009-06-18 17:41 Super- 阅读(3633) 评论(2)  编辑 收藏 引用

FeedBack:
# re: 关于release和debug中vector的疑问
2009-06-18 22:56 | Super-
vc在release时,加入了迭代子检测;
程序可以强制修改_SECURE_SCL为0,就可以解决问题了;  回复  更多评论
  
# re: 关于release和debug中vector的疑问
2013-08-09 20:37 | wy
@Super-
3q
  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理