[PATCH 3/3] builtin/apply: tighten (dis)similarity index parsing
- From
John Keeping <john@keeping.me.uk>
- Date
- Feb 3, 2013, 14:37 UTC
- Message-ID
- <2cac21192f79f9fbb5822417775954eba29064fa.1359901732.git.john@keeping.me.uk>
- In-Reply-To
- <cover.1359901732.git.john@keeping.me.uk>
This was prompted by an incorrect warning issued by clang [1], and a suggestion by Linus to restrict the range to check for values greater than INT_MAX since these will give bogus output after casting to int.
In fact the (dis)similarity index is a percentage, so reject values greater than 100.
[1] http://article.gmane.org/gmane.comp.version-control.git/213857
Signed-off-by: John Keeping <john@keeping.me.uk> --- builtin/apply.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c index 6c11e8b..4745e75 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1041,15 +1041,17 @@ static int gitdiff_renamedst(const char *line, struct patch *patch) static int gitdiff_similarity(const char *line, struct patch *patch) { - if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX) - patch->score = 0; + unsigned long val = strtoul(line, NULL, 10); + if (val <= 100) + patch->score = val; return 0; } static int gitdiff_dissimilarity(const char *line, struct patch *patch) { - if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX) - patch->score = 0; + unsigned long val = strtoul(line, NULL, 10); + if (val <= 100) + patch->score = val; return 0; }
-- 1.8.1.2