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>

John Keeping committed Feb 3, 2013 at 14:37 UTC afcb6ac83d8854f8cc271bb4e933836c9d4f1d3b
1 file changed +6 -4
builtin/apply.c
+6 -4
@@ -1041,15 +1041,17 @@ static int gitdiff_renamedst(const char *line, struct patch *patch)
1041
1042 static int gitdiff_similarity(const char *line, struct patch *patch)
1043 {
1044 - if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX)
1045 - patch->score = 0;
1044 + unsigned long val = strtoul(line, NULL, 10);
1045 + if (val <= 100)
1046 + patch->score = val;
1047 return 0;
1048 }
1049
1050 static int gitdiff_dissimilarity(const char *line, struct patch *patch)
1051 {
1051 - if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX)
1052 - patch->score = 0;
1052 + unsigned long val = strtoul(line, NULL, 10);
1053 + if (val <= 100)
1054 + patch->score = val;
1055 return 0;
1056 }
1057