trailer: use size_t for iterating trailer list

We store the length of the trailers list in a size_t. So on a 64-bit system with a 32-bit int, in the unlikely case that we manage to actually allocate a list with 2^31 entries, we'd loop forever trying to iterate over it (our "int" would wrap to negative before exceeding info->trailer_nr). This probably doesn't matter in practice. Each entry is at least a pointer plus a non-empty string, so even without malloc overhead or the memory to hold the original string we're parsing from, you'd need to allocate tens of gigabytes. But it's easy enough to do it right. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 22, 2018 at 20:45 UTC a3b636e21574e6cff1494e0a84644e06201ddb8d
2 files changed +4 -4
sequencer.c
+1 -1
@@ -225,7 +225,7 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
225 int ignore_footer)
226 {
227 struct trailer_info info;
228 - int i;
228 + size_t i;
229 int found_sob = 0, found_sob_last = 0;
230
231 trailer_info_get(&info, sb->buf);
trailer.c
+3 -3
@@ -948,7 +948,7 @@ static size_t process_input_file(FILE *outfile,
948 struct trailer_info info;
949 struct strbuf tok = STRBUF_INIT;
950 struct strbuf val = STRBUF_INIT;
951 - int i;
951 + size_t i;
952
953 trailer_info_get(&info, str);
954
@@ -1112,7 +1112,7 @@ void trailer_info_get(struct trailer_info *info, const char *str)
1112
1113 void trailer_info_release(struct trailer_info *info)
1114 {
1115 - int i;
1115 + size_t i;
1116 for (i = 0; i < info->trailer_nr; i++)
1117 free(info->trailers[i]);
1118 free(info->trailers);
@@ -1122,7 +1122,7 @@ static void format_trailer_info(struct strbuf *out,
1122 const struct trailer_info *info,
1123 const struct process_trailer_options *opts)
1124 {
1125 - int i;
1125 + size_t i;
1126
1127 /* If we want the whole block untouched, we can take the fast path. */
1128 if (!opts->only_trailers && !opts->unfold) {