int32 len = va_args(va, int32)在x86_64 GNU/Linux上给出非常大的值
int32 len = 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);
....
}
上面的代码在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页面也没有列出任何方法。
- 为什么在 Go 中将 float64 转换为 int32 会给出负数?
- 将 int32 重新解释为浮动
- 指针符号在参数规范中表示什么,例如:(char16 *缓冲区,int32 大小)?C++
- 概念侧类型'Converter.Session'中杆件'SessionId'的类型'Edm.Int32'与类型"系统"不匹配
- 从'float'到"int32"的C ++转换,可能会丢失数据
- 协议缓冲区 - 为什么 int32 和 sint32 以相同的方式映射
- 如何将INT32*转换为INT32
- 使用INT32的C :隐式转换失去整数精度
- 为什么有时人们更喜欢Strtoll而不是Strtol,即使他们只想将字符串转换为INT32
- 在 switch 语句中初始化变量 (int32)
- int32 溢出后可能的值是多少
- 在浮子中铸造Int32 NAN
- 逐位或在转换为int32之前
- 什么是C++翻译 Matlabs 'fread(fp, 1, 'int32')' 和 fread(fp, n, 'uchar')
- int32在所有平台上的大小是否相同?
- BinaryFormatter在转换Int32和Double等内部对象时出现问题
- 使用单个写操作写入多个VA位置
- int32 len = va_args(va, int32)在x86_64 GNU/Linux上给出非常大的值
- VA和内存地址
- Python 打包 int32 但不起作用?