| 1 | #include <cstdlib> |
| 2 | #include <stdint.h> |
| 3 | #include <string> |
| 4 | |
| 5 | template <typename T> struct CustomAlloc { |
| 6 | using value_type = T; |
| 7 | using pointer = value_type *; |
| 8 | using const_pointer = const value_type *; |
| 9 | using size_type = std::size_t; |
| 10 | |
| 11 | pointer allocate(size_type n) { return (T *)malloc(size: n * sizeof(T)); } |
| 12 | |
| 13 | void deallocate(pointer p, size_type) { |
| 14 | if (p) |
| 15 | free(p); |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | using CustomString = |
| 20 | std::basic_string<char, std::char_traits<char>, CustomAlloc<char>>; |
| 21 | |
| 22 | using CustomWString = |
| 23 | std::basic_string<wchar_t, std::char_traits<wchar_t>, CustomAlloc<wchar_t>>; |
| 24 | |
| 25 | using CustomStringU16 = std::basic_string<char16_t, std::char_traits<char16_t>, |
| 26 | CustomAlloc<char16_t>>; |
| 27 | |
| 28 | using CustomStringU32 = std::basic_string<char32_t, std::char_traits<char32_t>, |
| 29 | CustomAlloc<char32_t>>; |
| 30 | |
| 31 | size_t touch_string(std::string &in_str) { |
| 32 | return in_str.size(); // Break here to look at bad string |
| 33 | } |
| 34 | |
| 35 | int main() { |
| 36 | std::wstring wempty(L"" ); |
| 37 | std::wstring s(L"hello world! מזל טוב!" ); |
| 38 | std::wstring S(L"!!!!" ); |
| 39 | const wchar_t *mazeltov = L"מזל טוב" ; |
| 40 | std::string empty("" ); |
| 41 | std::string q("hello world" ); |
| 42 | std::string Q("quite a long std::strin with lots of info inside it" ); |
| 43 | std::string overwritten_zero("abc" ); |
| 44 | const_cast<char *>(overwritten_zero.data())[3] = 'd'; |
| 45 | std::string TheVeryLongOne( |
| 46 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 47 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 48 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 49 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 50 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 51 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 52 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 53 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 54 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 55 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 56 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 57 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 58 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 59 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 60 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 61 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 62 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 63 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 64 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 65 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 66 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 67 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 68 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 69 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 70 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 71 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 72 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 73 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 74 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 75 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 76 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 77 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 78 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 79 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 80 | "9012345678901234567890123456789012345678901234567890someText123456789012" |
| 81 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 82 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 83 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 84 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 85 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 86 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 87 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 88 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 89 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 90 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 91 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 92 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 93 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 94 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 95 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 96 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 97 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 98 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 99 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 100 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 101 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 102 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 103 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 104 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 105 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 106 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 107 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 108 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 109 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 110 | "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 111 | "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 112 | "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 113 | "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 114 | "901234567890123456789012345678901234567890123456789012345678901234567890" |
| 115 | "1234567890123456789012345678901234567890" ); |
| 116 | std::string IHaveEmbeddedZeros("a\0b\0c\0d" , 7); |
| 117 | std::wstring IHaveEmbeddedZerosToo( |
| 118 | L"hello world!\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監" , 38); |
| 119 | std::u16string u16_string(u"ß水氶" ); |
| 120 | std::u16string u16_empty(u"" ); |
| 121 | std::u32string u32_string(U"🍄🍅🍆🍌" ); |
| 122 | std::u32string u32_empty(U"" ); |
| 123 | std::string *null_str = nullptr; |
| 124 | auto &rq = q; |
| 125 | auto &rQ = Q; |
| 126 | std::string *pq = &q; |
| 127 | std::string *pQ = &Q; |
| 128 | |
| 129 | CustomString custom_str("hello!" ); |
| 130 | CustomWString custom_wstr(L"hello!" ); |
| 131 | CustomStringU16 custom_u16(u16_string.c_str()); |
| 132 | CustomStringU16 custom_u16_empty(u"" ); |
| 133 | CustomStringU32 custom_u32(u32_string.c_str()); |
| 134 | CustomStringU32 custom_u32_empty(U"" ); |
| 135 | |
| 136 | S.assign(s: L"!!!!!" ); // Set break point at this line. |
| 137 | std::string *not_a_string = (std::string *)0x0; |
| 138 | touch_string(in_str&: *not_a_string); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |