RSYNC 2.5.2 type mismatches in FLIST.C

John Malmberg wb8tyw at qsl.net
Mon Feb 11 02:48:33 EST 2002


Platform: OpenVMS Alpha 7.3
Compiler: Compaq C T6.5-002 on OpenVMS Alpha V7.3

Comile flags: /WARN=ENABLE=(LEVEL4, QUESTCODE)

Best guess at UNIX equivalents of above compile flags:

LEVEL4 = All warnings
QUESTCODE = Do LINT processing on source.


In flist.c, the result of a read_int(f) is being cast as a (dev_t) when 
it is being assigned to a (DEV64_T) type.  This breaks the build from a 
type mismatch.

Note in the case of a system that implements a 64 bit dev_t type, there 
is a lost of data, as only an int is read.  But I do not know what value 
a dev_t has between systems or the impact of the loss of data.

Then later in the module, the st.st_dev and st.st_ino members of a stat 
structure are being loaded into values that are DEV64_T and INO64_T 
types with out a cast.  This breaks the build from a type mismatch.

"file->dev = st.st_dev;"  should be "file->dev = (DEV64_T)st.st_rdev;"

In the same regard,
"file->inode = st.st_ino;" should be "file->inode = (INO64_T)st.st_ino;"

Except for as I pointed out in detail in my post on RECEIVER.C, the 
OpenVMS st_ino member is a 3 word array.  So my build procedure detects 
this and wraps it with a macro

The gnu diff below contains the VMS specific version of the above, plus 
fixes some issues where the "const" qualifier can improve the compiler 
optimizer.

Also the cast on the qsort() helper routine was wrong, and that was 
breaking my build.

-John
wb8tyw at qsl.network
Personal Opinion Only


EAGLE> type flist.gdiff
--- ref_src:flist.c     Sat Feb  9 21:17:30 2002
+++ lcl_src:flist.c     Sun Feb 10 09:11:20 2002
@@ -1,3 +1,24 @@
+/* Converted by prj_src:unix_c_to_vms_c.tpu AND PRJ_SRC:FLIST.TPU on 
10-FEB-2002 09:11:20.18 OPENVMS_AXP */
+#ifndef FRONTPORT_UNX_INO_T
+#undef FRONTPORT_UNX_INO_T
+#endif
+#ifndef FRONTPORT_VMS_INO_T
+#undef FRONTPORT_VMS_INO_T
+#endif
+#ifndef INO_T_CPY
+#ifdef __VMS
+#define INO_T_CPY(_a, _b) memcpy(_a, _b, 6)
+#else
+#define INO_T_CPY(_a, _b) _a = _b
+#endif
+#endif
+#ifndef INO_T_CMP
+#ifdef __VMS
+#define INO_T_CMP(_a, _b) memcmp(_a, _b, 6)
+#else
+#define INO_T_CMP(_a, _b) _a == _b
+#endif
+#endif
  /*
     Copyright (C) Andrew Tridgell 1996
     Copyright (C) Paul Mackerras 1996
@@ -506,7 +527,7 @@
                     (flags & SAME_GID) ? last_gid : (gid_t) read_int(f);
         if (preserve_devices && IS_DEVICE(file->mode))
                 file->rdev =
-                   (flags & SAME_RDEV) ? last_rdev : (dev_t) read_int(f);
+                   (flags & SAME_RDEV) ? last_rdev : (DEV64_T) read_int(f);

         if (preserve_links && S_ISLNK(file->mode)) {
                 int l = read_int(f);
@@ -514,7 +535,7 @@
                         rprintf(FERROR, "overflow: l=%d\n", l);
                         overflow("receive_file_entry");
                 }
-               file->link = (char *) malloc(l + 1);
+               file->link = malloc(l + 1);
                 if (!file->link)
                         out_of_memory("receive_file_entry 2");
                 read_sbuf(f, file->link, l);
@@ -535,7 +556,7 @@
  #endif

         if (always_checksum) {
-               file->sum = (char *) malloc(MD4_SUM_LENGTH);
+               file->sum = malloc(MD4_SUM_LENGTH);
                 if (!file->sum)
                         out_of_memory("md4 sum");
                 if (remote_version < 21) {
@@ -680,8 +701,8 @@
         file->mode = st.st_mode;
         file->uid = st.st_uid;
         file->gid = st.st_gid;
-       file->dev = st.st_dev;
-       file->inode = st.st_ino;
+       file->dev = (DEV64_T)st.st_dev;
+       INO_T_CPY(&file->inode, st.st_ino);
  #ifdef HAVE_STRUCT_STAT_ST_RDEV
         file->rdev = st.st_rdev;
  #endif
@@ -693,7 +714,7 @@
  #endif

         if (always_checksum) {
-               file->sum = (char *) MALLOC(ap, MD4_SUM_LENGTH);
+               file->sum = (unsigned char *) MALLOC(ap, MD4_SUM_LENGTH);
                 if (!file->sum)
                         out_of_memory("md4 sum");
                 /* drat. we have to provide a null checksum for non-regular
@@ -1090,7 +1111,7 @@
   * XXX: This is currently the hottest function while building the file
   * list, because building f_name()s every time is expensive.
   **/
-int file_compare(struct file_struct **f1, struct file_struct **f2)
+int file_compare(const struct file_struct * const *f1, const struct 
file_struct * const *f2)
  {
         if (!(*f1)->basename && !(*f2)->basename)
                 return 0;
@@ -1104,7 +1125,7 @@
  }


-int flist_find(struct file_list *flist, struct file_struct *f)
+int flist_find(const struct file_list *flist, const struct file_struct *f)
  {
         int low = 0, high = flist->count - 1;

@@ -1114,7 +1135,7 @@
         while (low != high) {
                 int mid = (low + high) / 2;
                 int ret =
-                   file_compare(&flist->files[flist_up(flist, mid)], &f);
+                   file_compare((const struct file_struct * const 
*)&flist->files[flist_up(flist, mid)], &f);
                 if (ret == 0)
                         return flist_up(flist, mid);
                 if (ret > 0) {
@@ -1124,7 +1145,7 @@
                 }
         }

-       if (file_compare(&flist->files[flist_up(flist, low)], &f) == 0)
+       if (file_compare((const struct file_struct * const 
*)&flist->files[flist_up(flist, low)], &f) == 0)
                 return flist_up(flist, low);
         return -1;
  }
@@ -1150,7 +1171,7 @@
  /*
   * allocate a new file list
   */
-struct file_list *flist_new()
+struct file_list *flist_new(void)
  {
         struct file_list *flist;

@@ -1207,7 +1228,7 @@
                 return;

         qsort(flist->files, flist->count,
-             sizeof(flist->files[0]), (int (*)()) file_compare);
+             sizeof(flist->files[0]), (int (*)(const void *, const void 
*))file_compare);

         for (i = 1; i < flist->count; i++) {
                 if (flist->files[i]->basename &&
@@ -1274,7 +1295,7 @@
   * strings when often we only want to compare them.  In any case,
   * using strlcat is silly because it will walk the string repeatedly.
   */
-char *f_name(struct file_struct *f)
+char *f_name(const struct file_struct *f)
  {
         static char names[10][MAXPATHLEN];
         static int n;
EAGLE>






More information about the rsync mailing list