1 #include <string>
2 #include <unordered_map>
3 #include <unordered_set>
4 
5 int g_the_foo = 0;
6 
thefoo_rw(int arg=1)7 int thefoo_rw(int arg = 1) {
8   if (arg < 0)
9     arg = 0;
10   if (!arg)
11     arg = 1;
12   g_the_foo += arg;
13   return g_the_foo;
14 }
15 
main()16 int main() {
17 
18   char buffer[sizeof(std::unordered_map<int, std::string>)] = {0};
19   std::unordered_map<int, std::string> &corrupt_map = *(std::unordered_map<int, std::string> *)buffer;
20 
21   std::unordered_map<int, std::string> map; // Set break point at this line.
22   map.emplace(1, "hello");
23   map.emplace(2, "world");
24   map.emplace(3, "this");
25   map.emplace(4, "is");
26   map.emplace(5, "me");
27   thefoo_rw(); // Set break point at this line.
28 
29   std::unordered_multimap<int, std::string> mmap;
30   mmap.emplace(1, "hello");
31   mmap.emplace(2, "hello");
32   mmap.emplace(2, "world");
33   mmap.emplace(3, "this");
34   mmap.emplace(3, "this");
35   mmap.emplace(3, "this");
36   thefoo_rw(); // Set break point at this line.
37 
38   std::unordered_set<int> iset;
39   iset.emplace(1);
40   iset.emplace(2);
41   iset.emplace(3);
42   iset.emplace(4);
43   iset.emplace(5);
44   thefoo_rw(); // Set break point at this line.
45 
46   std::unordered_set<std::string> sset;
47   sset.emplace("hello");
48   sset.emplace("world");
49   sset.emplace("this");
50   sset.emplace("is");
51   sset.emplace("me");
52   thefoo_rw(); // Set break point at this line.
53 
54   std::unordered_multiset<int> imset;
55   imset.emplace(1);
56   imset.emplace(2);
57   imset.emplace(2);
58   imset.emplace(3);
59   imset.emplace(3);
60   imset.emplace(3);
61   thefoo_rw(); // Set break point at this line.
62 
63   std::unordered_multiset<std::string> smset;
64   smset.emplace("hello");
65   smset.emplace("world");
66   smset.emplace("world");
67   smset.emplace("is");
68   smset.emplace("is");
69   thefoo_rw(); // Set break point at this line.
70 
71   return 0;
72 }
73