Commit 05cbd84 1 parent 84b9321 commit 05cbd84 Copy full SHA for 05cbd84
File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -173,13 +173,24 @@ class string
173
173
return *this ;
174
174
}
175
175
176
- // no longer allowed!
177
- _IRR_DEBUG_BREAK_IF ((void *)c == (void *)c_str ());
176
+ if constexpr (sizeof (T) != sizeof (B)) {
177
+ _IRR_DEBUG_BREAK_IF (
178
+ (uintptr_t )c >= (uintptr_t )(str.data ()) &&
179
+ (uintptr_t )c < (uintptr_t )(str.data () + str.size ()));
180
+ }
181
+
182
+ if ((void *)c == (void *)c_str ())
183
+ return *this ;
178
184
179
185
u32 len = calclen (c);
180
- str.resize (len);
186
+ // In case `c` is a pointer to our own buffer, we may not resize first
187
+ // or it can become invalid.
188
+ if (len > str.size ())
189
+ str.resize (len);
181
190
for (u32 l = 0 ; l < len; ++l)
182
- str[l] = (T)c[l];
191
+ str[l] = static_cast <T>(c[l]);
192
+ if (len < str.size ())
193
+ str.resize (len);
183
194
184
195
return *this ;
185
196
}
You can’t perform that action at this time.
0 commit comments