the signed/unsigned change seems to have caused a logic bug on some
[rsync/rsync.git] / flist.c
diff --git a/flist.c b/flist.c
index 341dcf4..96ed47f 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -95,6 +95,12 @@ static void finish_build_progress(const struct file_list *flist)
 }
 
 
+void show_flist_stats(void)
+{
+       /* Nothing yet */
+}
+
+
 static struct string_area *string_area_new(int size)
 {
        struct string_area *a;
@@ -266,13 +272,46 @@ static void send_directory(int f, struct file_list *flist, char *dir);
 static char *flist_dir;
 
 
+/**
+ * Make sure @p flist is big enough to hold at least @p flist->count
+ * entries.
+ **/
+static void flist_expand(struct file_list *flist)
+{
+       if (flist->count >= flist->malloced) {
+               size_t new_bytes;
+               void *new_ptr;
+               
+               if (flist->malloced < 1000)
+                       flist->malloced += 1000;
+               else
+                       flist->malloced *= 2;
+
+               new_bytes = sizeof(flist->files[0]) * flist->malloced;
+               
+               new_ptr = realloc(flist->files, new_bytes);
+
+               if (verbose >= 2) {
+                       rprintf(FINFO, RSYNC_NAME ": expand file_list to %.0f bytes, did%s move\n",
+                               (double) new_bytes,
+                               (new_ptr == flist->files) ? " not" : "");
+               }
+               
+               flist->files = (struct file_struct **) new_ptr;
+
+               if (!flist->files)
+                       out_of_memory("flist_expand");
+       }
+}
+
+
 static void send_file_entry(struct file_struct *file, int f,
                            unsigned base_flags)
 {
        unsigned char flags;
        static time_t last_time;
        static mode_t last_mode;
-       static dev_t last_rdev;
+       static DEV64_T last_rdev;
        static uid_t last_uid;
        static gid_t last_gid;
        static char lastname[MAXPATHLEN];
@@ -391,7 +430,7 @@ static void receive_file_entry(struct file_struct **fptr,
 {
        static time_t last_time;
        static mode_t last_mode;
-       static dev_t last_rdev;
+       static DEV64_T last_rdev;
        static uid_t last_uid;
        static gid_t last_gid;
        static char lastname[MAXPATHLEN];
@@ -643,7 +682,7 @@ struct file_struct *make_file(int f, char *fname, struct string_area **ap,
        file->gid = st.st_gid;
        file->dev = st.st_dev;
        file->inode = st.st_ino;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STRUCT_STAT_ST_RDEV
        file->rdev = st.st_rdev;
 #endif
 
@@ -700,19 +739,7 @@ void send_file_name(int f, struct file_list *flist, char *fname,
        if (show_build_progress_p() & !(flist->count % 100))
                emit_build_progress(flist);
 
-       if (flist->count >= flist->malloced) {
-               if (flist->malloced < 1000)
-                       flist->malloced += 1000;
-               else
-                       flist->malloced *= 2;
-               flist->files =
-                   (struct file_struct **) realloc(flist->files,
-                                                   sizeof(flist->
-                                                          files[0]) *
-                                                   flist->malloced);
-               if (!flist->files)
-                       out_of_memory("send_file_name");
-       }
+       flist_expand(flist);
 
        if (write_batch)        /*  dw  */
                file->flags = FLAG_DELETE;
@@ -953,7 +980,7 @@ struct file_list *send_file_list(int f, int argc, char *argv[])
        }
 
        if (f != -1) {
-               io_end_buffering(f);
+               io_end_buffering();
                stats.flist_size = stats.total_written - start_write;
                stats.num_files = flist->count;
                if (write_batch)        /*  dw  */
@@ -996,22 +1023,8 @@ struct file_list *recv_file_list(int f)
 
        for (flags = read_byte(f); flags; flags = read_byte(f)) {
                int i = flist->count;
-
-               if (i >= flist->malloced) {
-                       if (flist->malloced < 1000)
-                               flist->malloced += 1000;
-                       else
-                               flist->malloced *= 2;
-                       flist->files =
-                           (struct file_struct **) realloc(flist->files,
-                                                           sizeof(flist->
-                                                                  files
-                                                                  [0]) *
-                                                           flist->
-                                                           malloced);
-                       if (!flist->files)
-                               goto oom;
-               }
+               
+               flist_expand(flist);
 
                receive_file_entry(&flist->files[i], flags, f);
 
@@ -1146,12 +1159,9 @@ struct file_list *flist_new()
                out_of_memory("send_file_list");
 
        flist->count = 0;
-       flist->malloced = 1000;
-       flist->files =
-           (struct file_struct **) malloc(sizeof(flist->files[0]) *
-                                          flist->malloced);
-       if (!flist->files)
-               out_of_memory("send_file_list");
+       flist->malloced = 0;
+       flist->files = NULL;
+
 #if ARENA_SIZE > 0
        flist->string_area = string_area_new(0);
 #else
@@ -1171,6 +1181,10 @@ void flist_free(struct file_list *flist)
                        free_file(flist->files[i]);
                free(flist->files[i]);
        }
+       /* FIXME: I don't think we generally need to blank the flist
+        * since it's about to be freed.  This will just cause more
+        * memory traffic.  If you want a freed-memory debugger, you
+        * know where to get it. */
        memset((char *) flist->files, 0,
               sizeof(flist->files[0]) * flist->count);
        free(flist->files);