When is it appropriate to edit someone else's code?
Intuitively I would think the following guidelines would be appropriate:
Minor or subtle bugs: Edit the code to fix the bug, retaining the original author's intent.
Major bugs or fundamental flaws: Provide your own answer without those bugs or flaws, or comment on the answer.
However, an edit I suggested to a very old, slightly wrong answer was rejected by two users. So, I gather my intuitions don't match SO users' conventions (or possibly, there's something wrong with my suggestion that is not adequately described by their reasons for rejection).
What factors determine whether it is appropriate to edit somebody else's code to fix a bug?