【问题标题】:Crash when using boost::iostreams使用 boost::iostreams 时崩溃
【发布时间】:2013-04-01 20:03:31
【问题描述】:

我正在尝试使用 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 来构建和运行代码。

你们之前有遇到过这样的问题吗?

【问题讨论】:

  • 你能附加一个调试器并发布崩溃的堆栈跟踪吗?
  • 你确认 argv[1] 确实指向一个文件吗?
  • @Zac gzip_decompressor() 崩溃与提供的 argv 无关。不过,它指向正确的文件路径。

标签: c++ boost gzip boost-iostreams compression


【解决方案1】:

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

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

感谢您的回复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    相关资源
    最近更新 更多