Boost文件系统路径中的分割故障
Segmentation fault in boost file system path
i在验证类中具有成员函数,该类别为一组文件生成哈希。
,该代码正确编译了,尽管当软件达到哈希功能时,它会抛出SEG故障。我一直在寻找年龄,但看不到它。这似乎与路径向量和复制功能有关。
Program received signal SIGSEGV, Segmentation fault.
0x000055c84fbbc058 in std::vector<boost::filesystem::path, std::allocator<boost::filesystem::path> >::push_back(boost::filesystem::path const&) ()
(gdb)
Single stepping until exit from function _ZNSt6vectorIN5boost10filesystem4pathESaIS2_EE9push_backERKS2_,
which has no line number information.
Program terminated with signal SIGSEGV, Segmentation fault.
从GDB
输出代码下面:
#pragma once
#include <boost/filesystem.hpp>
#include <cryptopp/cryptlib.h>
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <cryptopp/md5.h>
#include "cryptopp/hex.h"
#include "cryptopp/files.h"
class Verify {
private:
typedef std::vector<boost::filesystem::path> vec;
vec v;
public:
bool verify_files();
bool generate_hash(boost::filesystem::path source);
};
功能实施
bool Verify::generate_hash(boost::filesystem::path source) {
try {
if (boost::filesystem::exists(source)) { //make sure path is valid
if (boost::filesystem::is_regular_file(source)) { //no regular files
std::cout << "Please enter base path of directory only." << std::endl;
return false;
}
else if (boost::filesystem::is_directory(source)){ //process directory here
std::cout << "Scanning " << source << std::endl;
std::copy(boost::filesystem::recursive_directory_iterator(source), boost::filesystem::recursive_directory_iterator(), std::back_inserter(this->v));
std::sort(v.begin(), v.end());
for (vec::const_iterator it (v.begin()); it != v.end(); ++it){
std::string result;
if (boost::filesystem::is_regular_file(*it)) {
Weak::MD5 hash;
FileSource((*it).string().c_str(), true, new HashFilter(hash, new HexEncoder(new StringSink(result), false)));
}
std::cout << "Hashing: " << *it << " - " << result << std::endl;
}
}
}
} catch (const boost::filesystem::filesystem_error& e){
std::cout << e.what() << std::endl;
return false;
}
return true;
}
您的错误在此行上:
std::copy(boost::filesystem::recursive_directory_iterator(source), boost::filesystem::recursive_directory_iterator(), std::back_inserter(this->v));
您应该在此处进行手动循环,以进一步调查(如果没有消除问题(
相关文章:
- 分割故障C++矩阵
- C ,二进制树的高度,而不是检查我的子树是否为空,而是在检查我的子树是否是叶子节点.抛出分割故障
- 我正在为此代码分割故障
- 在执行strcpy时获取分割故障错误
- 空隙指针分割故障
- Xcode会产生分割故障,而不是例外
- OPENCV C 中的分割故障误差
- 分割故障:核心倾倒C 矢量对字符串:
- C 2D数组导致分割故障(核心倾倒)
- 分割故障/错误读数变量-C 列表
- DLSYM导致分割故障
- 使用C 中的操作员删除的分割故障
- 使用Linux X64下的Libmozjs-52(SpidermonKey)进行分割故障
- 使用长变量时分割故障(11)错误
- C - 返回字符串时的分割故障
- 创建VertexArray时的分割故障
- 向量分割故障的向量
- 从std :: fileSystem ::路径对象的类中退出时的分割故障
- C 矢量分割故障
- 基于向量的数据格式的分割故障误差