Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对C++代码静态检查类对象初始化的问题 #5

Closed
freeeyes opened this issue Oct 16, 2017 · 2 comments
Closed

对C++代码静态检查类对象初始化的问题 #5

freeeyes opened this issue Oct 16, 2017 · 2 comments

Comments

@freeeyes
Copy link

freeeyes commented Oct 16, 2017

C++代码
好像如果在构造内存中,添加Init()初始化函数。
也就是在构造函数中嵌套的情况下,如果我在Init()里面初始化类对象,会提示
Message: Member variable 'CBuffPacket::m_szData,m_u4ReadPtr,m_u4WritePtr,m_u4PacketLen,m_u4PacketCount,m_u4MaxPacketSize,m_blNetSort,m_nHashID,m_u4BuffID,' is not initialized in the constructor.
类似这样的代码,代码静态检查可否加上对嵌套函数内部的检查呢?
各位辛苦了
样例

CBuffPacket::CBuffPacket(int nSize, int nMaxBuffSize)
{
    if (false == Init(nSize, nMaxBuffSize))
    {
        OUR_DEBUG((LM_INFO, "[CBuffPacket::CBuffPacket]Error(%s).\n", m_szError));
    }
}

bool CBuffPacket::Init(int nSize, int nMaxBuffSize)
{
    //ACE_Guard<ACE_Recursive_Thread_Mutex> WGuard(m_ThreadLock);
    try
    {
        m_szError[0]      = '\0';
        m_u4MaxPacketSize = (uint32)nMaxBuffSize;

        if(nSize >= (int)m_u4MaxPacketSize)
        {
            OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d] is more than m_u4MaxPacketSize.\n", nSize));
            char szError[MAX_BUFF_500] = {'\0'};
            sprintf_safe(szError, MAX_BUFF_500, "[CBuffPacket::Init] nSize [%d] is more than m_u4MaxPacketSize.", nSize);
            throw szError;
        }

        //初始化包数据结构
        m_u4ReadPtr       = 0;
        m_u4WritePtr      = 0;
        m_u4PacketCount   = 0;
        m_nHashID         = 0;
        m_u4PacketLen     = (uint32)((int)ceil((double)nSize/(double)DEFINE_PACKET_ADD))*DEFINE_PACKET_ADD;

        m_szData          = (char*)App_ACEMemory::instance()->malloc(m_u4PacketLen);
        m_u4BuffID        = 0;

        //OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d], m_szData=[0x%08x].\n", m_u4PacketLen, m_szData));

        if(NULL == m_szData)
        {
            OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d] is new error.\n", m_u4PacketLen));
            char szError[MAX_BUFF_500] = {'\0'};
            sprintf_safe(szError, MAX_BUFF_500, "[CBuffPacket::Init] nSize [%d] is new error..", m_u4PacketLen);
            throw szError;
        }

        m_blNetSort = false;

        return true;
    }
    catch(const char* szError)
    {
        sprintf_safe(m_szError, MAX_BUFF_500, "%s", szError);
        return false;
    }
}
@ben620
Copy link
Collaborator

ben620 commented Oct 16, 2017

你好,感谢您对TscanCode工具的支持和反馈,我们已经收录该条问题。该问题原因在于构造函数检查没有支持跨函数分析。初始化相关检查已经有部分跨函数分析能力,我们会在下一个版本中增加对以上场景的支持,请关注。

@freeeyes
Copy link
Author

谢谢,辛苦了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants