我正在调试一个实际上是文件阅读器的代码。代码运行,但在某些行之后我收到错误:
*** glibc detected *** /bin/OPENSUSE_12.2_X86_64/filereader: corrupted double-linked list: 0x0000000003608dc0 ***
调试后我理解问题来自一个名为ReadLongVector
的函数,函数初始化和定义如下。问题出在else循环中:
bool floatDS, retVal
if ( floatDS ) {
retVal = ReadLongVector( floatvec_, 3*numZoneNodes,
velPath, zonePath.str(),
timeStepNumbers_[timeStepIdx], false );
} else {
retVal = ReadLongVector( doublevec_, 3*numZoneNodes,
velPath, zonePath.str(),
timeStepNumbers_[timeStepIdx], false );
}
ReadLongVector
功能如下:
template<typename T>
bool ReadLongVector(std::vector<T> &out,
Integer size,
std::string what,
std::string where,
Integer when,
bool throwEx)
{
int dattyp;
int length = 1;
int iopt = __not_stop_if_failed__;
int nerr = 0;
T *datarray;
if (size < 1) size = 1;
out.resize(size*length);
datarray = out.data();
const std::type_info &tiOut = typeid(T);
if ( tiOut == typeid(float) ) {
dattyp = __real_data_type__;
} else if ( tiOut == typeid(int) || tiOut == typeid(unsigned int) ) {
dattyp = __int_data_type__;
} else if ( tiOut == typeid(double) ) {
dattyp = __double_data_type__;
} else {
if (throwEx) EXCEPTION("Data type not supported: " << tiOut.name());
return false;
}
snprintf(what_, sizeof(what_), "%s", what.c_str());
snprintf(where_, sizeof(where_), "%s", where.c_str());
readlong_(&dattyp, &nerr,
what_, where_, &when,
&size, &iopt,
(float*)datarray, (int*)datarray, NULL, NULL, (double*)datarray, NULL,
strlen(what_), strlen(where_), 0);
if ( nerr == __io_ok__ ) {
return true;
} else {
if ( throwEx ) CHECK_CFX_IO(nerr);
return false;
}
}
任何帮助表示赞赏,提前致谢。