Tencent / TscanCode

A static code analyzer for C++, C#, Lua
Other
2.01k stars 591 forks source link

请教一个提示问题 #6

Open freeeyes opened 7 years ago

freeeyes commented 7 years ago

首先感谢工具非常好用,谢谢作者的辛苦。 我有一段测试代码 //文件测试数据信息

typedef struct FILETESTDATAINFO
{
    char                    m_szData[MAX_BUFF_10240];        //当前缓冲中数据的长度
    uint32                  m_u4DataLength;                  //当前缓冲块中的数据长度

    FILETESTDATAINFO()
    {
        ACE_OS::memset(m_szData, 0, MAX_BUFF_10240);
        m_u4DataLength = 0;
    }

    FILETESTDATAINFO(const FILETESTDATAINFO& ar)
    {
        ACE_OS::memset(m_szData, 0, MAX_BUFF_10240);

        if (false == memcpy_safe(const_cast<char*>(ar.m_szData), MAX_BUFF_10240, const_cast<char*>(this->m_szData), MAX_BUFF_10240))
        {
            OUR_DEBUG((LM_INFO, "[FILETESTDATAINFO::FILETESTDATAINFO]memcpy_safe error.\n"));
        }

        this->m_u4DataLength = ar.m_u4DataLength;
    }

    void Close()
    {
        ACE_OS::memset(m_szData, 0, MAX_BUFF_10240);
        m_u4DataLength     = 0;
    }

    ~FILETESTDATAINFO()
    {
        Close();
    }

    FILETESTDATAINFO& operator= (const FILETESTDATAINFO& ar)
    {
        if (false == memcpy_safe(const_cast<char*>(ar.m_szData), MAX_BUFF_10240, const_cast<char*>(this->m_szData), MAX_BUFF_10240))
        {
            OUR_DEBUG((LM_INFO, "[FILETESTDATAINFO::FILETESTDATAINFO]operator= error.\n"));
        }

        this->m_u4DataLength = ar.m_u4DataLength;
        return *this;
    }
} FileTestDataInfoSt;

为什么检验的时候提示我 Type: FuncReturn Line: XXX Message: The return value of function [Close] is not used. 我的 Close()是一个void 类型 没有返回值呀?

类似的代码还有(提示我Close接口返回值没有使用)

//中间服务器消息类接口
class IPostMessage
{
public:
    IPostMessage()
    {
        m_pRecvPacket = NULL;
        m_pSendPacket = NULL;
        m_u4ServerID  = 0;
        m_u2CommandID = 0;
        m_blDelete    = true;
    }

    virtual ~IPostMessage()
    {
        Close();
    }

    virtual void Close()
    {
        if(NULL != m_pRecvPacket)
        {
            delete m_pRecvPacket;
            m_pRecvPacket = NULL;
        }

        if(NULL != m_pSendPacket)
        {
            delete m_pSendPacket;
            m_pSendPacket = NULL;
        }

        m_u4ServerID  = 0;
        m_u2CommandID = 0;
        m_blDelete    = true;
    }

    virtual bool SetRecvPacket(IBuffPacket* pRecvPacket)
    {
        if(NULL == pRecvPacket)
        {
            return false;
        }

        m_pRecvPacket = pRecvPacket;
        return true;
    }

    virtual bool SetSendPacket(IBuffPacket* pSendPacket)
    {
        if(NULL == pSendPacket)
        {
            return false;
        }

        m_pSendPacket = pSendPacket;
        return true;
    }

    virtual IBuffPacket*  GetRecvPacket()
    {
        return m_pRecvPacket;
    }

    virtual IBuffPacket*  GetSendPacket()
    {
        return m_pSendPacket;
    }

    virtual void CallBefore()              = 0;
    virtual void CallBack()                = 0;

    virtual void   SetServerID(uint32 u4ServerID)
    {
        m_u4ServerID = u4ServerID;
    }

    virtual uint32 GetServerID()
    {
        return m_u4ServerID;
    }

    virtual void   SetCommandID(uint16 u2CommandID)
    {
        m_u2CommandID = u2CommandID;
    }

    virtual uint16 GetCommandID()
    {
        return m_u2CommandID;
    }

private:
    IBuffPacket* m_pRecvPacket;
    IBuffPacket* m_pSendPacket;
    uint32       m_u4ServerID;
    uint16       m_u2CommandID;
    bool         m_blDelete;
};
ben620 commented 7 years ago

感谢支持与持续反馈。FuncReturn这条规则属于默认未开启的规则,规则准确性目前还不太高。你反馈的这条问题我们还需要排查。