在sphinx中修复此问题的想法

时间:2014-07-02 11:14:23

标签: c++ c sphinx

bool NetOutputBuffer_c::SendVectorBytes ( const void * pBuf, int iLen,vector<string> &vec )
{
        BYTE * pMy = (BYTE*)pBuf;
        while ( iLen>0 && !m_bError )
        {
                int iLeft = m_iBufferSize - ( m_pBufferPtr-m_pBuffer );
                printf("iLeft is %d\n",iLeft);
                if ( iLen<=iLeft )
                {
                        printf("iLen is %d\n",iLen);
                        memcpy ( m_pBufferPtr, pMy, iLen );
                        printf("m_pBuffer is %s\n",(char*)m_pBufferPtr);
                        vec.push_back((char*)m_pBufferPtr);
                        vec.push_back("\n");
                        m_pBufferPtr += iLen;
                        break;
                }

                ResizeIf ( iLen );
        }
        return !m_bError;
}

i)在此函数中,传递以下参数

     const void *pBuf -> Buffer 
     iLen ->length of the string to be pushed into the vector(gets the string from the buffer depending on the iLen(length) what we are passing)
     vec ->To push the data's in to vector(stl) depending up on the value of iLen 

ii)我们正在将void *转换为Byte *,就像这样

  BYTE * pMy = (BYTE*)pBuf;

iii)ILeft是剩余的总缓冲区大小(它不会导致任何问题)

iv)如果(iLen&lt; = iLeft)并且进入循环内部它满足以下条件。

v)memcpy(m_pBufferPtr,pMy,iLen);

      Depending on the length of ilen,it gets the data from pMy and stores it into the m_pBufferPtr...

当我运行程序时,我正在获得这样的输出

iLeft is 8059
    iLen is 74
    m_pBuffer is this is my tests document number one. also checking search within phrases.



iLeft is 7965
    iLen is 8
    m_pBuffer is test two


    iLeft is 7953
    iLen is 36
    m_pBuffer is this is my tests document number two

iLeft is 7897
    iLen is 9
    m_pBuffer is test five

iLeft is 7884
    iLen is 75
    m_pBuffer is this is my tests document number five. also checking search within phrases.


iLeft is 7789
    iLen is 8
    m_pBuffer is test six

iLeft is 7777
    iLen is 36
    m_pBuffer is this is my tests document number six


iLeft is 7721
    iLen is 10
    m_pBuffer is test seven


    iLeft is 7707
    iLen is 76
    m_pBuffer is this is my tests document number seven. also checking search within phrases.�������


   iLeft is 7611
   iLen is 10
   m_pBuffer is test eight

   iLeft is 7597
   iLen is 38
   m_pBuffer is this is my tests document number eight


   iLeft is 7539
   iLen is 9
   m_pBuffer is test nine����������

  iLeft is 7526
  iLen is 75
  m_pBuffer is this is my tests document number nine. also checking search within phrases.


 For test seven and test nine , even though the iLen value was perfect,it contains some
  garbage values...

            iLeft is 7707
            iLen is 76(total 76 six characters starting from this )
            m_pBuffer is this is my tests document number seven. also checking search within
            phrases.�������


            m_pBuffer is test nine����������

谢谢&amp;问候, Udaya Chandran S

1 个答案:

答案 0 :(得分:0)

我认为*m_pBufferPtr中的测试字符串最后没有终止(转义)字符\0。 查看here了解更多信息。