我正在尝试使用boost::iostreams(1.53.0)解压缩HTTP请求正文并稍后对其进行处理。
但是,当我运行以下代码时,我崩溃了。

try {
    using namespace boost::iostreams;
    ifstream file(argv[1], std::ios_base::in | std::ios_base::binary);
    boost::iostreams::filtering_istream in;
    in.push(gzip_decompressor());
    in.push(file);
    std::stringstream strstream;
    boost::iostreams::copy(in, strstream);
} catch (std::exception& e) {
    cout << e.what() << endl;
}

崩溃发生在gzip_decompressor()中,更具体而言,发生在boost的gzip.hpp中的gzip_header() { reset(); }中(通过查看调用堆栈)。

我已经编译了boost::iostreams库,也尝试从macports使用boost,但是发生了同样的崩溃。我也尝试过使用gzstream library,但是这也会在构造函数中崩溃,更具体地说,在igzstream的构造函数中也会崩溃。

我倾向于认为这是与zlib有关的问题。
我没有指定,我正在使用带有Mountain Lion和xCode 4.6的MacBook Pro来构建和运行代码。

你们有没有遇到过这样的问题?

最佳答案

我发现了问题:Apple的LLVM编译器。
我确定我在使用GCC,但似乎没有。

我是通过绊倒另一个奇怪的崩溃而发现的,该崩溃只是通过实例化std::string对象而发生。这使我检查了项目设置,发现我正在使用LLVM编译器,这可能对我链接gcc构建的库不满意。

多谢您的回覆。

关于c++ - 使用boost::iostreams时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15750878/

10-12 00:07
查看更多