As reported by bb in #4531, the map Corsica vs Sardinia completely fails to generate on many map seeds, probably since the map was introduced.
This is because it tries to paint the beaches outside of the map border.
So adding a simple check for map boundaries fixes the issue. If someone comes up with a better formula, feel free to post it.