Mercurial > hg > mercurial-source
changeset 38977:b8b253aec953 stable
mpatch: introduce a safesub() helper as well
Same reason as safeadd().
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 03 May 2018 12:54:20 -0400 (2018-05-03) |
parents | 1ec4cb8cbc87 |
children | 0b208c13781c |
files | mercurial/mpatch.c |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/mpatch.c +++ b/mercurial/mpatch.c @@ -88,6 +88,17 @@ return true; } +/* subtract src from dest and store result in dest */ +static inline bool safesub(int src, int *dest) +{ + if (((src > 0) && (*dest < INT_MIN + src)) || + ((src < 0) && (*dest > INT_MAX + src))) { + return false; + } + *dest -= src; + return true; +} + /* move hunks in source that are less cut to dest, compensating for changes in offset. the last hunk may be split if necessary. */