2 Answers
2

In that specific case, yes. The code is broken, and anyone with experience in that language will see that the revised version is provably more correct than the original version. The original version has a bug that will work 99% of the time, but it's that 1% that will absolutely kill someone trying to debug the whole program. Please don't allow bad and wrong code to exist on stackoverflow if you are given tools to fix it.

In the same way that we fix bad grammar for the sake of clarity, we should fix bad code for the sake of good development and easy debugging.

However, as others have pointed out, such edits should only be accepted if you are certain that the code is wrong and not just because you prefer a different technique or style.

When in doubt, ignore it to let another reviewer with possibly more experience fix it, or reject it if you have a strong suspicion that the edit is worse.

IMHO, code should nearly always come from the poster him/herself, since it provides the substance of the answer. Unless it's Community Wiki, outside edits should just be a way of making the poster's point more clear (via formatting, cleaning up the English, etc.), without changing what the user is saying. Once you change the code, you're taking over the answer rather than clarifying it.

It might be appropriate to do this in the case of misinformation or something similar, but it seems to me that that's what downvotes are for.