int32 len = va_args(va, int32)在x86_64 GNU/Linux上给出非常大的值


void AppBuf(message_id_type msgID, int32 numPairs, va_list va)
{
int32 len = va_args(va, int32);
....
}

上面的代码在windows(32位和64位)和linux 32位编译器上运行得很好。对于以上所有内容,'len'的值为10。

但是在linux 64位(x86_64 GNU/linux)上,我得到了len (50462976)的非常大的值,这混淆了其余的代码并最终导致崩溃。

我读到linux 64位编译器在va_lists方面发生了变化,但我无法理解这种变化,所以我无法解决我的问题。

有人能帮我解决这个问题吗?

谢谢。阳光

好的,这里是整个代码的细节导致这一点:有人能帮帮忙吗?提前谢谢。

调用栈:

AppendBuffers(int msgID=0x00000001, int numPairs=0x00000001, char * va=0x0007fcb0) {注意:这是上面提到的问题发生的地方(长度=非常大)}

LogMsg(int msgID=0x00000001, int numPairs=0x00000001, char * arguments=0x0007fcb0)

LogMsgBuffersV(int msgID=0x00000001, int numPairs=0x00000001, char * arguments=0x0007fcb0)

LogMsgBuffersV(int msgID=0x00000001, int numPairs=0x00000001, char * arguments=0x0007fcb0)

LogMsgBuffers(int msgID=0x00000001, int numPairs=0x00000001,…)

实际代码:

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);
        }

AFACIT, va_args不是标准函数。事实上,除了__VA_ARGS__宏之外,谷歌还把这个问题作为最重要的答案之一。

实际上没有标准的方法来确定给定的va_list中有多少va_arg参数,并且GCC页面也没有列出任何方法。

相关内容

  • 没有找到相关文章

最新更新