vector<string>& words;
sort(words.begin(), words.end(), [](const string &str1, const string &str2) {
return str1.size() > str2.size();
});
我的目的是将 words 中的 string 按照长度排序 (words 中大概有 1k 个 string)
但是 lambda 函数中的比较如果是 >= 的话, 就会报错, heap buffer overflow
AddressSanitizer: heap-buffer-overflow on address 0x63000000fe08 at pc 0x000000411eff bp 0x7ffcfab095c0 sp 0x7ffcfab095b8
我的迷惑是 :
堆溢出? 怎么溢出的?
为什么 > 就可以?
1
AlohaV2 2019-07-27 09:27:34 +08:00 via Android 1
能否再贴完整一些的代码?
|
2
richard1122 2019-07-27 09:29:30 +08:00 3
"Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines."
因为返回 bool 要保证 comp(a, b) 和 comp(b, a) 是只有一个 true 的,在相等时候不可以返回 true |
3
richard1122 2019-07-27 09:30:29 +08:00
|