(c++) va_args(va, int32) gives very large value on x86_64 GNU/Linux

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.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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);
        }
Last edited on
Topic archived. No new replies allowed.