2 ms·
Simple example: shared_ptr<int> global; void func(const shared_ptr<int>& v) { global.reset(); *v += 1; // ohno } func(global);
by ridiculous_fish 7y ago
Simple example:
shared_ptr<int> global;
void func(const shared_ptr<int>& v) {
global.reset();
*v += 1; // ohno
}
func(global);
- PaulDavisThe1st 7y agofair enough, but that's fairly stupid programming :) /* XXX the argument might be the same as the global value we're about to modify. API designers, eh? */
- MaulingMonkey 7y agoDoesn't have to be global - could be a member that gets modified in a callback, or that goes out of scope because something else gets deconstructed. I'd also like to inquire as to what nontrivial codebase you've seen that contains no fairly stupid programming. I keep hearing about them, and trying to prove their existence, but so far I've collected more concrete evidence for the existence of bigfoot than I have for the existence of such codebases.