@matheusbsbs / matheus-bagliano / commits / 2386c2975d
Fork 0

combine-diff.c: type sanity

- combine_diff() took cnt (count) which is unsigned in nature but the parameter type was declared as "int"; - find_next() took "uninteresting" parameter, which masked a static function of the same name; - show_parent_lno() took an unused parameter "cnt"; - show_patch_diff() used a local variable in nested inner scope with the same name with different type, masking the one in the outer scope; - the last loop in show_patch_diff iterated over lines so it should use the local variable "lno" Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 28, 2006 at 01:38 UTC 2386c2975d66e03d02a9ebf15a1d07092975e527
1 file changed +15 -14
combine-diff.c
+15 -14
@@ -205,7 +205,8 @@ static void consume_line(void *state_, char *line, unsigned long len)
205 }
206
207 static void combine_diff(const unsigned char *parent, mmfile_t *result_file,
208 - struct sline *sline, int cnt, int n, int num_parent)
208 + struct sline *sline, unsigned int cnt, int n,
209 + int num_parent)
210 {
211 unsigned int p_lno, lno;
212 unsigned long nmask = (1UL << n);
@@ -293,7 +294,7 @@ static unsigned long find_next(struct sline *sline,
294 unsigned long mark,
295 unsigned long i,
296 unsigned long cnt,
296 - int uninteresting)
297 + int look_for_uninteresting)
298 {
299 /* We have examined up to i-1 and are about to look at i.
300 * Find next interesting or uninteresting line. Here,
@@ -303,7 +304,7 @@ static unsigned long find_next(struct sline *sline,
304 * that are surrounded by interesting() ones.
305 */
306 while (i <= cnt)
306 - if (uninteresting
307 + if (look_for_uninteresting
308 ? !(sline[i].flag & mark)
309 : (sline[i].flag & mark))
310 return i;
@@ -489,7 +490,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
490 return has_interesting;
491 }
492
492 -static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, unsigned long cnt, int n)
493 +static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n)
494 {
495 l0 = sline[l0].p_lno[n];
496 l1 = sline[l1].p_lno[n];
@@ -523,7 +524,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
524 rlines--; /* pointing at the last delete hunk */
525 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
526 for (i = 0; i < num_parent; i++)
526 - show_parent_lno(sline, lno, hunk_end, cnt, i);
527 + show_parent_lno(sline, lno, hunk_end, i);
528 printf(" +%lu,%lu ", lno+1, rlines);
529 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
530 putchar('\n');
@@ -619,18 +620,18 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
620 if (0 <= (fd = open(elem->path, O_RDONLY)) &&
621 !fstat(fd, &st)) {
622 int len = st.st_size;
622 - int cnt = 0;
623 + int sz = 0;
624
625 elem->mode = canon_mode(st.st_mode);
626 result_size = len;
627 result = xmalloc(len + 1);
627 - while (cnt < len) {
628 - int done = xread(fd, result+cnt, len-cnt);
628 + while (sz < len) {
629 + int done = xread(fd, result+sz, len-sz);
630 if (done == 0)
631 break;
632 if (done < 0)
633 die("read error '%s'", elem->path);
633 - cnt += done;
634 + sz += done;
635 }
636 result[len] = 0;
637 }
@@ -645,7 +646,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
646 close(fd);
647 }
648
648 - for (cnt = 0, cp = result; cp - result < result_size; cp++) {
649 + for (cnt = 0, cp = result; cp < result + result_size; cp++) {
650 if (*cp == '\n')
651 cnt++;
652 }
@@ -658,7 +659,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
659 sline[lno].lost_tail = &sline[lno].lost_head;
660 sline[lno].flag = 0;
661 }
661 - for (lno = 0, cp = result; cp - result < result_size; cp++) {
662 + for (lno = 0, cp = result; cp < result + result_size; cp++) {
663 if (*cp == '\n') {
664 sline[lno].len = cp - sline[lno].bol;
665 lno++;
@@ -739,9 +740,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
740 }
741 free(result);
742
742 - for (i = 0; i < cnt; i++) {
743 - if (sline[i].lost_head) {
744 - struct lline *ll = sline[i].lost_head;
743 + for (lno = 0; lno < cnt; lno++) {
744 + if (sline[lno].lost_head) {
745 + struct lline *ll = sline[lno].lost_head;
746 while (ll) {
747 struct lline *tmp = ll;
748 ll = ll->next;