开发者

int32 len = va_args(va, int32) gives very large value on x86_64 GNU/Linux

开发者 https://www.devze.com 2023-03-21 20:11 出处:网络
void AppBuf(message_id_type msgID, int32 numPairs, va_list va) { int32 len = va_args(va, int32); .... } The above piece of code runs perfectly fine on windows (32 and 64 bit) and also on linux 32 b
void AppBuf(message_id_type msgID, int32 numPairs, va_list va)

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

The above piece of code runs perfectly fine on windows (32 and 64 bit) and also on linux 32 bit compiler. Value of 'len' comes out to 10 for all the above.

But on linux 64 bit (x86_64 GNU/Linux) I am getting a very large value for len (50462976), which messes up the rest of the code and end ups in a crash.

I had read that something has changed in linux 64 bit compilers with respect to va_lists but I was not able to understand the change and so I was not able to fix my issue.

Could someone please help me with this issue?

Thanks.

Sunny

Ok, here are the details of the whole code leading upto this point: Could someone please help with this? Thanks in advance.

Call Stack:

AppendBuffers(int msgID=0x00000001, int numPairs=0x00000001, char * va=0x0007fcb0) {NOTE: this is where the problem is occuring as mentioned above (length = very large)}

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, ...)

Actual code:

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]);
                }
            }
          开发者_Python百科  va_end(va);
        }


AFACIT, va_args is not a standard function. In fact, Google is turning up this question as one of its top answers, besides __VA_ARGS__ macros.

There's in fact no standard way to determine how many va_arg arguments are in a given va_list, and the GCC page doesn't list any method either.

0

精彩评论

暂无评论...
验证码 换一张
取 消