2011-07-19 40 views
0
void AppBuf(message_id_type msgID, int32 numPairs, va_list va) 

{ 
int32 len = va_args(va, int32); 
.... 
} 

上面一段代碼非常大的值上運行的窗口(32位和64位)完全正常,並且還在Linux 32位編譯器。 'len'的值爲10以上所有。但是在Linux 64位(x86_64 GNU/Linux)上,我得到了一個非常大的值len50462976),它弄亂了代碼的其餘部分,並在崩潰中結束了ups。INT32 LEN = va_args(VA,INT32)給出在x86_64 GNU/Linux的

我讀過linux 64位編譯器相對於va_lists的一些變化,但我無法理解這個變化,所以我無法解決我的問題。

有人可以幫我解決這個問題嗎?

謝謝。

陽光

好吧,這裏是整個代碼領先高達這點的細節: 可能有人請幫助這個?提前致謝。

調用堆棧:

AppendBuffers(INT MSGID = 00000001,INT numPairs = 00000001,字符* VA = 0x0007fcb0){注意:這是在上述(長度=非常大如提到的問題是發生)}

LogMsg(INT MSGID = 00000001,INT numPairs = 00000001,字符*參數= 0x0007fcb0)

LogMsgBuffersV(INT MSGID = 00000001,INT numPairs = 00000001,字符*參數= 0x0007fcb0)

LogMsgBuffersV(INT MSGID = 00000001,INT numPairs = 00000001,字符*參數= 0x0007fcb0)

LogMsgBuffers(INT MSGID = 00000001,INT numPairs = 00000001,...)

實際代碼:

void LogMsgBuffers(message_id_type msgID, int32 numPairs, ...) 
{ 

    va_list arguments; 
    va_start(arguments, numPairs); 

    filter_status_type msgStatus = FilterMsg(msgID); 

    if (msgStatus == FILTER_ACCEPT) 
    { 
     LogMsg(msgID, numPairs, arguments); 
    } 

    if ((_parentLogger != NULL) && (_oAppenderInheritance)) 
    { 
     //Pass the msg to the parent 
     _parentLogger->LogMsgBuffersV(msgID, numPairs, arguments); 
    } 

    return; 
} 

void LogMsgBuffersV(message_id_type msgID, int32 numPairs, va_list arguments) 
{ 

    filter_status_type msgStatus = FilterMsg(msgID); 

    if (msgStatus == FILTER_ACCEPT) 
    { 
     //Log msg to the current node 
     LogMsg(msgID, numPairs, arguments); 
    } 

    if ((_parentLogger != NULL) && (_oAppenderInheritance)) 
    { 
     //Pass the msg to the parent 
     _parentLogger->LogMsgBuffersV(msgID, numPairs, arguments); 

    } 
    return; 
} 

void LogMsgBuffersV(message_id_type msgID, int32 numPairs, va_list arguments) 
{ 
    filter_status_type msgStatus = FilterMsg(msgID); 

    if (msgStatus == FILTER_ACCEPT) 
    { 
     //Log msg to the current node 
     LogMsg(msgID, numPairs, arguments); 
    } 

    if ((_parentLogger != NULL) && (_oAppenderInheritance)) 
    { 
     //Pass the msg to the parent 
     _parentLogger->LogMsgBuffersV(msgID, numPairs, arguments); 

    } 
    return; 
} 

void LogMsg(message_id_type msgID, int32 numPairs, va_list arguments) 
{ 
    uint32 i; 

    for (i = 0; i < _pOwnAppenderVec.size(); i++) 
    { 
     LoggerAppender *appender = _pOwnAppenderVec[i]; 
     appender->AppendBuffers(msgID, numPairs, arguments); 
    } 
    return; 
} 

void AppendBuffers(message_id_type msgID, int32 numPairs, va_list va) 
     { 

      for (int32 i = 0; i < numPairs; i++) 
      { 
       int32 length = va_arg(va, int32); 
       uint8* buffer = va_arg(va, uint8*); 

       int32 jj; 
       for (jj = 10; jj < length; jj += 10) 
       { 
        AppendStringA(0, " %x %x %x %x %x %x %x %x %x %x", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9]); 
        buffer += 10; 
       } 

       uint8 remainderbuf[10]; 
       uint32 remainder = length - (jj - 10); 
       if (remainder > 0 && remainder <= 10) 
       { 
        oscl_memcpy(remainderbuf, buffer, remainder); 
        oscl_memset(remainderbuf + remainder, 0, 10 - remainder); 
        buffer = remainderbuf; 
        AppendStringA(0, " %x %x %x %x %x %x %x %x %x %x", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9]); 
       } 
      } 
      va_end(va); 
     } 
+2

你怎麼稱呼上面的代碼? – ybungalobill

+0

可能是調用代碼在該特定配置上錯誤地填充了列表?例如,它可能會傳遞非POD類型。 – sharptooth

+0

請勿使用'va_list'。如果您需要可變參數,請使用可變參數模板,生成的重載或其他類型安全的方法。 –

回答

5

AFACIT,va_args不是標準功能。實際上,除了__VA_ARGS__宏之外,谷歌正在將這個問題作爲其最佳答案之一。

事實上沒有標準的方法可以確定在給定的va_list中有多少個va_arg參數,並且the GCC page也沒有列出任何方法。

相關問題