bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] xheader.c: wrong cast


From: Paul Eggert
Subject: Re: [Bug-tar] xheader.c: wrong cast
Date: Tue, 12 Dec 2006 15:59:23 -0800
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Trond Hasle Amundsen <address@hidden> writes:

> Solaris' C compiler choked on xheader.c in tar-1.16.1:
>
>   "xheader.c", line 1097: operands have incompatible types:
>            struct timespec {long tv_sec, long tv_nsec} ":" const struct 
> timespec {long tv_sec, long tv_nsec}
>   cc: acomp failed for xheader.c

Thanks for reporting that.  Also, the cast in that area gives me the
willies.  Also, I just now tried to build tar 1.16.1 on an older
Solaris implementation (Solaris 8 with Forte Developer 7 C 5.4) and
found some other diagnostics, some of which are real compatibility
bugs.

I installed the following.

2006-12-12  Paul Eggert  <address@hidden>

        Port to Forte Developer 7 C 5.4 and C99.
        * src/common.h (add_exclude_tag): Add decl; C99 requires this
        and Forte warns about it.
        * src/incremen.c: Include <mkdtemp.h> for mkdtemp prototype,
        for same reason.
        * src/misc.c (get_max_open_files): Rewrite to avoid code that
        Forte C complains about as being unreachable.
        * src/xheader.c (mtime_code): Rewrite to avoid Forte error
        reported by Trond Hasle Amundsen.

        * src/incremen.c (compare_dirnames): Rewrite to avoid casts.
        * src/utf8.c (string_ascii_p): Likewise.
        * src/xheader.c (mtime_coder, volume_size_coder, volume_offset_coder):
        Likewise.

Index: src/common.h
===================================================================
RCS file: /cvsroot/tar/tar/src/common.h,v
retrieving revision 1.92
diff -p -u -b -w -r1.92 common.h
--- src/common.h        30 Nov 2006 06:39:29 -0000      1.92
+++ src/common.h        12 Dec 2006 23:55:30 -0000
@@ -417,6 +417,7 @@ enum dump_status
     dump_status_not_implemented
   };
 
+void add_exclude_tag (const char *name);
 bool file_dumpable_p (struct tar_stat_info *st);
 void create_archive (void);
 void pad_archive (off_t size_left);
Index: src/incremen.c
===================================================================
RCS file: /cvsroot/tar/tar/src/incremen.c,v
retrieving revision 1.51
diff -p -u -b -w -r1.51 incremen.c
--- src/incremen.c      8 Sep 2006 16:45:41 -0000       1.51
+++ src/incremen.c      12 Dec 2006 23:55:30 -0000
@@ -20,6 +20,7 @@
 #include <system.h>
 #include <getline.h>
 #include <hash.h>
+#include <mkdtemp.h>
 #include <quotearg.h>
 #include "common.h"
 
@@ -378,7 +379,9 @@ dumpdir_size (const char *p)
 static int
 compare_dirnames (const void *first, const void *second)
 {
-  return strcmp (*(const char**)first, *(const char**)second);
+  char const *const *name1 = first;
+  char const *const *name2 = second;
+  return strcmp (*name1, *name2);
 }
 
 /* Compare dumpdir array from DIRECTORY with directory listing DIR and
Index: src/misc.c
===================================================================
RCS file: /cvsroot/tar/tar/src/misc.c,v
retrieving revision 1.36
diff -p -u -b -w -r1.36 misc.c
--- src/misc.c  4 Jul 2006 21:52:05 -0000       1.36
+++ src/misc.c  12 Dec 2006 23:55:30 -0000
@@ -1,7 +1,7 @@
 /* Miscellaneous functions, not really specific to GNU tar.
 
    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
-   2003, 2004, 2005 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -588,10 +588,12 @@ get_max_open_files ()
 
   if (getrlimit(RLIMIT_NOFILE, &rlim) == 0)
     return rlim.rlim_max;
+  return -1;
 #elif defined HAVE_GETDTABLESIZE
   return getdtablesize ();
-#endif
+#else
   return -1;
+#endif
 }
 
 /* Close all descriptors, except the first three */
Index: src/utf8.c
===================================================================
RCS file: /cvsroot/tar/tar/src/utf8.c,v
retrieving revision 1.8
diff -p -u -b -w -r1.8 utf8.c
--- src/utf8.c  15 May 2005 03:59:10 -0000      1.8
+++ src/utf8.c  12 Dec 2006 23:55:30 -0000
@@ -1,6 +1,6 @@
 /* Charset handling for GNU tar.
 
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -88,11 +88,10 @@ utf8_convert (bool to_utf, char const *i
 
 
 bool
-string_ascii_p (const char *str)
+string_ascii_p (char const *p)
 {
-  const unsigned char *p = (const unsigned char *)str;
   for (; *p; p++)
-    if (*p > 127)
+    if (! (0 <= *p && *p <= 127))
       return false;
   return true;
 }
Index: src/xheader.c
===================================================================
RCS file: /cvsroot/tar/tar/src/xheader.c,v
retrieving revision 1.49
diff -p -u -b -w -r1.49 xheader.c
--- src/xheader.c       30 Nov 2006 09:53:20 -0000      1.49
+++ src/xheader.c       12 Dec 2006 23:55:30 -0000
@@ -1094,8 +1094,8 @@ static void
 mtime_coder (struct tar_stat_info const *st, char const *keyword,
             struct xheader *xhdr, void const *data)
 {
-  const struct timespec mtime = data ? *(struct timespec *) data : st->mtime;
-  code_time (mtime, keyword, xhdr);
+  struct timespec const *mtime = data;
+  code_time (mtime ? *mtime : st->mtime, keyword, xhdr);
 }
 
 static void
@@ -1379,8 +1379,8 @@ static void
 volume_size_coder (struct tar_stat_info const *st, char const *keyword,
                   struct xheader *xhdr, void const *data)
 {
-  off_t v = *(off_t*)data;
-  code_num (v, keyword, xhdr);
+  off_t const *v = data;
+  code_num (*v, keyword, xhdr);
 }
 
 static void
@@ -1398,8 +1398,8 @@ static void
 volume_offset_coder (struct tar_stat_info const *st, char const *keyword,
                     struct xheader *xhdr, void const *data)
 {
-  off_t v = *(off_t*)data;
-  code_num (v, keyword, xhdr);
+  off_t const *v = data;
+  code_num (*v, keyword, xhdr);
 }
 
 static void





reply via email to

[Prev in Thread] Current Thread [Next in Thread]