mpatch: rewrite pointer overflow checks

--HG--
branch : stable
extra : rebase_source : 9b7374d750bff084674f152c7cf0f1e28b2c5fd5
hgweb: avoid initialization race (issue3953)

--HG--
branch : stable
extra : rebase_source : ef2f82a29d85f20e0029e1ff3d2a3edd1e024c4f