Code

xsize_t: check whether we lose bits
[git.git] / builtin-rerere.c
index 079c0bdf36abce6a34af2678f7efbb56dfcfdf41..b8867ab4add83dee4ab99108e96949bcd65290a0 100644 (file)
@@ -51,9 +51,11 @@ static int write_rr(struct path_list *rr, int out_fd)
        int i;
        for (i = 0; i < rr->nr; i++) {
                const char *path = rr->items[i].path;
-               write(out_fd, rr->items[i].util, 40);
-               write(out_fd, "\t", 1);
-               write(out_fd, path, strlen(path) + 1);
+               int length = strlen(path) + 1;
+               if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
+                   write_in_full(out_fd, "\t", 1) != 1 ||
+                   write_in_full(out_fd, path, length) != length)
+                       die("unable to write rerere record");
        }
        close(out_fd);
        return commit_lock_file(&write_lock);
@@ -103,11 +105,11 @@ static int handle_file(const char *path,
                SHA1_Init(&ctx);
 
        while (fgets(buf, sizeof(buf), f)) {
-               if (!strncmp("<<<<<<< ", buf, 8))
+               if (!prefixcmp(buf, "<<<<<<< "))
                        hunk = 1;
-               else if (!strncmp("=======", buf, 7))
+               else if (!prefixcmp(buf, "======="))
                        hunk = 2;
-               else if (!strncmp(">>>>>>> ", buf, 8)) {
+               else if (!prefixcmp(buf, ">>>>>>> ")) {
                        hunk_no++;
                        hunk = 0;
                        if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
@@ -152,13 +154,17 @@ static int find_conflict(struct path_list *conflict)
                return error("Could not read index");
        for (i = 0; i + 2 < active_nr; i++) {
                struct cache_entry *e1 = active_cache[i];
-               struct cache_entry *e2 = active_cache[i + 1];
-               struct cache_entry *e3 = active_cache[i + 2];
-               if (ce_stage(e1) == 1 && ce_stage(e2) == 2 &&
-                               ce_stage(e3) == 3 && ce_same_name(e1, e2) &&
-                               ce_same_name(e1, e3)) {
+               struct cache_entry *e2 = active_cache[i+1];
+               struct cache_entry *e3 = active_cache[i+2];
+               if (ce_stage(e1) == 1 &&
+                   ce_stage(e2) == 2 &&
+                   ce_stage(e3) == 3 &&
+                   ce_same_name(e1, e2) && ce_same_name(e1, e3) &&
+                   S_ISREG(ntohl(e1->ce_mode)) &&
+                   S_ISREG(ntohl(e2->ce_mode)) &&
+                   S_ISREG(ntohl(e3->ce_mode))) {
                        path_list_insert((const char *)e1->name, conflict);
-                       i += 3;
+                       i += 2;
                }
        }
        return 0;
@@ -244,7 +250,8 @@ static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
 {
        int i;
        for (i = 0; i < nbuf; i++)
-               write(1, ptr[i].ptr, ptr[i].size);
+               if (write_in_full(1, ptr[i].ptr, ptr[i].size) != ptr[i].size)
+                       return -1;
        return 0;
 }