2013-04-04 59 views
10

我是尽我所能缩小下来,这似乎是一个错误......这是libC++ std :: search_n的崩溃吗?

#include <algorithm> 
#include <vector> 

int main(int argc, char *argv[]) 
{ 
    // Crashes 
    std::vector<uint8_t> bs{1, 0, 0}; 
    std::search_n(bs.begin(), bs.end(), 3, 1); 

    // Does not crash 
    std::vector<uint8_t> bs{1, 0}; 
    std::search_n(bs.begin(), bs.end(), 2, 1); 

    return 0; 
} 

我得到

Segmentation fault: 11 

我希望我没有使用std :: search_n错误:)

使用LLDB目前看起来不可能使用STL实现。

版本信息:

$clang --version 
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) 
Target: x86_64-apple-darwin12.3.0 
Thread model: posix 

证据;)

13:06:47 ~/bug$ cat bug.cc 
#include <algorithm> 
#include <vector> 

int main(int argc, char *argv[]) 
{ 
    std::vector<uint8_t> bs{1, 0, 0}; 
    std::search_n(bs.begin(), bs.end(), 3, 1); 

    // std::vector<uint8_t> bs{1, 0}; 
    // std::search_n(bs.begin(), bs.end(), 2, 1); 

    return 0; 
} 
13:06:52 ~/bug$ clang++ -std=c++11 -stdlib=libc++ bug.cc -o bug 
13:07:36 ~/bug$ ./bug 
Segmentation fault: 11 
13:07:42 ~/bug$ 
+0

不会崩溃与叮当3.2:[http://liveworkspace.org/code/tRPXH$2](http://liveworkspace.org/code/tRPXH$2) – interjay 2013-04-04 11:53:05

+0

工作正常与GNU libstdC++,并没有什么可疑的是你使用了'find_n'(除非你没有使用返回值,而使用这些输入的搜索将始终失败)。 – 2013-04-04 11:54:23

+0

@interjay但是使用libC++或libstdC++的liveworkspace? – 2013-04-04 11:56:29

回答

6

这似乎是在search_n一个错误,它崩溃对我来说太(4.6.1的Xcode)。我认为在__search_n测试

if (__first == __s) // return __last if no element matches __value_ 

需求是

if (__first >= __s) // return __last if no element matches __value_ 

什么情况是,该算法开始匹配,那么不匹配,然后重新开始;这个新的起点超出__s,这是模式长度的逻辑上最后可能的起点。旧的测试只测试平等,而不是“超越”。修复它不会再让我崩溃。

+0

我想这应该提交,你有一个帐户来做到这一点? http://llvm.org/bugs/enter_bug.cgi – dpj 2013-04-04 13:20:51

+0

不,我不知道。 (添加字符以满足15个字符的要求) – Dix 2013-04-04 13:25:41

+1

创建了一个帐户,提交了一个bug:http://llvm.org/bugs/show_bug.cgi?id=15667 – Dix 2013-04-04 14:19:49