这是在libc中崩溃std :: search_n一个错误?
发布时间:2020-12-16 05:32:41 所属栏目:百科 来源:网络整理
导读:我尽可能缩小了这一点,似乎是一个错误 #include algorithm#include vectorint main(int argc,char *argv[]){ // Crashes std::vectoruint8_t bs{1,0}; std::search_n(bs.begin(),bs.end(),3,1); // Does not crash std::vectoruint8_t bs{1,2,1); return 0;}
我尽可能缩小了这一点,似乎是一个错误
#include <algorithm> #include <vector> int main(int argc,char *argv[]) { // Crashes std::vector<uint8_t> bs{1,0}; std::search_n(bs.begin(),bs.end(),3,1); // Does not crash std::vector<uint8_t> bs{1,2,1); return 0; } 我得到 Segmentation fault: 11 我希望我没有使用std :: search_n不正确:) 目前,使用LLDB的方法似乎不可行. 版本信息: $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,1); // std::vector<uint8_t> bs{1,0}; // std::search_n(bs.begin(),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$ 解决方法
它似乎是search_n中的一个错误,它也为我崩溃(Xcode 4.6.1).我认为在__search_n测试
if (__first == __s) // return __last if no element matches __value_ 需要是 if (__first >= __s) // return __last if no element matches __value_ 发生什么是该算法开始匹配,然后不匹配并重新开始;这个新的起始点超出了__s,它是模式长度的逻辑最后可能的起始点.旧的测试只是测试了平等,而不是“超越”.有了修复,它不会为我崩溃. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |