0 c++ linux x86-64 variadic-functions
void AppBuf(message_id_type msgID, int32 numPairs, va_list va)
{
int32 len = va_args(va, int32);
....
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
395 次 |
| 最近记录: |