Issue #5251: fix hidden overflow

Well, this is my first PR, so I hope everything is ok.
Please keep the indentation and perhaps add some new lines around the new code.