下一个被munmap_chunk()破坏的代码:无效指针
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> modules = {3,5,7};
vector<int> remainders = {2,3,2};
vector<int> m_bigs(modules.size());
int main() {
int m_big = 1;
for(int r : remainders) { m_big *= r; };
transform(m_bigs.begin(), m_bigs.end(), remainders.begin(), remainders.end(), [m_big](int m, int r){ cout << m_big / r << endl; return m_big / r; });
for(int m : m_bigs) { cout << m << endl; };
return 0;
}
输出是
6 4 6 4 6 0
但预期是
6 4 6 6 4 6