summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2013-02-03 14:37:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-02-03 21:47:43 (GMT)
commitafcb6ac83d8854f8cc271bb4e933836c9d4f1d3b (patch)
tree766574ff9ac7b39150a4d1a088e0f2f972768e5e /builtin/apply.c
parent7e2010537e96d0a1144520222f20ba1dc3d61441 (diff)
downloadgit-afcb6ac83d8854f8cc271bb4e933836c9d4f1d3b.zip
git-afcb6ac83d8854f8cc271bb4e933836c9d4f1d3b.tar.gz
git-afcb6ac83d8854f8cc271bb4e933836c9d4f1d3b.tar.bz2
builtin/apply: tighten (dis)similarity index parsing
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r--builtin/apply.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index ca8695a..fd2b40e 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;
}