diff options
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | gl/lib/rand-isaac.c | 24 | ||||
-rw-r--r-- | gl/lib/randread.c | 10 | ||||
-rw-r--r-- | src/expr.c | 14 | ||||
-rw-r--r-- | src/ls.c | 38 | ||||
-rw-r--r-- | src/sort.c | 3 | ||||
-rw-r--r-- | src/system.h | 11 | ||||
-rw-r--r-- | src/tail.c | 4 |
8 files changed, 76 insertions, 43 deletions
diff --git a/configure.ac b/configure.ac index 3f0c58b9e..8a3ac48a0 100644 --- a/configure.ac +++ b/configure.ac @@ -164,6 +164,21 @@ if test "$gl_gcc_warnings" = yes; then # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c gl_WARN_ADD([-Wno-logical-op]) + # clang is unduly picky about some things. + AC_CACHE_CHECK([whether the compiler is clang], [utils_cv_clang], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #ifndef __clang__ + #error "not clang" + #endif + ]])], + [utils_cv_clang=yes], + [utils_cv_clang=no])]) + if test $utils_cv_clang = yes; then + gl_WARN_ADD([-Wno-format-extra-args]) + gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare]) + fi + gl_WARN_ADD([-fdiagnostics-show-option]) gl_WARN_ADD([-funit-at-a-time]) diff --git a/gl/lib/rand-isaac.c b/gl/lib/rand-isaac.c index defd21778..04af2e782 100644 --- a/gl/lib/rand-isaac.c +++ b/gl/lib/rand-isaac.c @@ -58,16 +58,26 @@ just (isaac_word a) return a & desired_bits; } -/* The index operation. On typical machines whose words are exactly - the right size, this is optimized to a mask, an addition, and an - indirect load. Atypical machines need more work. */ +/* The index operation. */ static inline isaac_word ind (isaac_word const *m, isaac_word x) { - return (sizeof *m * CHAR_BIT == ISAAC_BITS - ? (* (isaac_word *) ((char *) m - + (x & ((ISAAC_WORDS - 1) * sizeof *m)))) - : m[(x / (ISAAC_BITS / CHAR_BIT)) & (ISAAC_WORDS - 1)]); + if (sizeof *m * CHAR_BIT == ISAAC_BITS) + { + /* The typical case, where words are exactly the right size. + Optimize this to a mask, an addition, and an indirect + load. */ + void const *void_m = m; + char const *base_p = void_m; + void const *word_p = base_p + (x & ((ISAAC_WORDS - 1) * sizeof *m)); + isaac_word const *p = word_p; + return *p; + } + else + { + /* Atypical machines need more work. */ + return m[(x / (ISAAC_BITS / CHAR_BIT)) & (ISAAC_WORDS - 1)]; + } } /* Use and update *S to generate random data to fill RESULT. */ diff --git a/gl/lib/randread.c b/gl/lib/randread.c index dfba61182..8ee384751 100644 --- a/gl/lib/randread.c +++ b/gl/lib/randread.c @@ -275,12 +275,14 @@ readsource (struct randread_source *s, unsigned char *p, size_t size) the buffered ISAAC generator in ISAAC. */ static void -readisaac (struct isaac *isaac, unsigned char *p, size_t size) +readisaac (struct isaac *isaac, void *p, size_t size) { size_t inbytes = isaac->buffered; while (true) { + char *char_p = p; + if (size <= inbytes) { memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, size); @@ -289,14 +291,14 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size) } memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, inbytes); - p += inbytes; + p = char_p + inbytes; size -= inbytes; /* If P is aligned, write to *P directly to avoid the overhead of copying from the buffer. */ if (ALIGNED_POINTER (p, isaac_word)) { - isaac_word *wp = (isaac_word *) p; + isaac_word *wp = p; while (ISAAC_BYTES <= size) { isaac_refill (&isaac->state, wp); @@ -308,7 +310,7 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size) return; } } - p = (unsigned char *) wp; + p = wp; } isaac_refill (&isaac->state, isaac->data.w); diff --git a/src/expr.c b/src/expr.c index b4fa808a0..9d21ca87f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -44,8 +44,6 @@ int, the widest unsigned type that GMP supports. */ verify (SIZE_MAX <= ULONG_MAX); -static void integer_overflow (char) ATTRIBUTE_NORETURN; - #ifndef HAVE_GMP # define HAVE_GMP 0 #endif @@ -53,6 +51,7 @@ static void integer_overflow (char) ATTRIBUTE_NORETURN; #if HAVE_GMP # include <gmp.h> #else +static void integer_overflow (char) ATTRIBUTE_NORETURN; /* Approximate gmp.h well enough for expr.c's purposes. */ typedef intmax_t mpz_t[1]; static void mpz_clear (mpz_t z) { (void) z; } @@ -278,6 +277,7 @@ syntax_error (void) error (EXPR_INVALID, 0, _("syntax error")); } +#if ! HAVE_GMP /* Report an integer overflow for operation OP and exit. */ static void integer_overflow (char op) @@ -285,15 +285,7 @@ integer_overflow (char op) error (EXPR_FAILURE, ERANGE, "%c", op); abort (); /* notreached */ } - -static void die (int errno_val, char const *msg) - ATTRIBUTE_NORETURN; -static void -die (int errno_val, char const *msg) -{ - error (EXPR_FAILURE, errno_val, "%s", msg); - abort (); /* notreached */ -} +#endif int main (int argc, char **argv) @@ -962,25 +962,33 @@ static struct obstack subdired_obstack; static struct obstack dev_ino_obstack; /* Push a pair onto the device/inode stack. */ -#define DEV_INO_PUSH(Dev, Ino) \ - do \ - { \ - struct dev_ino *di; \ - obstack_blank (&dev_ino_obstack, sizeof (struct dev_ino)); \ - di = -1 + (struct dev_ino *) obstack_next_free (&dev_ino_obstack); \ - di->st_dev = (Dev); \ - di->st_ino = (Ino); \ - } \ - while (0) +static void +dev_ino_push (dev_t dev, ino_t ino) +{ + void *vdi; + struct dev_ino *di; + int dev_ino_size = sizeof *di; + obstack_blank (&dev_ino_obstack, dev_ino_size); + vdi = obstack_next_free (&dev_ino_obstack); + di = vdi; + di--; + di->st_dev = dev; + di->st_ino = ino; +} /* Pop a dev/ino struct off the global dev_ino_obstack and return that struct. */ static struct dev_ino dev_ino_pop (void) { - assert (sizeof (struct dev_ino) <= obstack_object_size (&dev_ino_obstack)); - obstack_blank (&dev_ino_obstack, -(int) (sizeof (struct dev_ino))); - return *(struct dev_ino *) obstack_next_free (&dev_ino_obstack); + void *vdi; + struct dev_ino *di; + int dev_ino_size = sizeof *di; + assert (dev_ino_size <= obstack_object_size (&dev_ino_obstack)); + obstack_blank (&dev_ino_obstack, -dev_ino_size); + vdi = obstack_next_free (&dev_ino_obstack); + di = vdi; + return *di; } /* Note the use commented out below: @@ -1978,7 +1986,7 @@ decode_switches (int argc, char **argv) if (file_type <= indicator_style) { char const *p; - for (p = "*=>@|" + indicator_style - file_type; *p; p++) + for (p = &"*=>@|"[indicator_style - file_type]; *p; p++) set_char_quoting (filename_quoting_options, *p, 1); } @@ -2542,7 +2550,7 @@ print_dir (char const *name, char const *realname, bool command_line_arg) return; } - DEV_INO_PUSH (dir_stat.st_dev, dir_stat.st_ino); + dev_ino_push (dir_stat.st_dev, dir_stat.st_ino); } if (recursive || print_dir_name) diff --git a/src/sort.c b/src/sort.c index 7410abca6..062b5f946 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1557,7 +1557,8 @@ initbuf (struct buffer *buf, size_t line_bytes, size_t alloc) static inline struct line * buffer_linelim (struct buffer const *buf) { - return (struct line *) (buf->buf + buf->alloc); + void *linelim = buf->buf + buf->alloc; + return linelim; } /* Return a pointer to the first character of the field specified diff --git a/src/system.h b/src/system.h index 94c968fbd..db8931635 100644 --- a/src/system.h +++ b/src/system.h @@ -496,21 +496,24 @@ ptr_align (void const *ptr, size_t alignment) Note the word after the buffer must be non NUL. */ static inline bool _GL_ATTRIBUTE_PURE -is_nul (const char *buf, size_t bufsize) +is_nul (void const *buf, size_t bufsize) { typedef uintptr_t word; + void const *vp; + char const *cbuf = buf; + word const *wp = buf; /* Find first nonzero *word*, or the word with the sentinel. */ - word *wp = (word *) buf; while (*wp++ == 0) continue; /* Find the first nonzero *byte*, or the sentinel. */ - char *cp = (char *) (wp - 1); + vp = wp - 1; + char const *cp = vp; while (*cp++ == 0) continue; - return cp > buf + bufsize; + return cbuf + bufsize < cp; } /* If 10*Accum + Digit_val is larger than the maximum value for Type, diff --git a/src/tail.c b/src/tail.c index 6bbc7251f..0f1a37c07 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1446,6 +1446,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, { struct File_spec *fspec; struct inotify_event *ev; + void *void_ev; /* When following by name without --retry, and the last file has been unlinked or renamed-away, diagnose it and return. */ @@ -1507,7 +1508,8 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, error (EXIT_FAILURE, errno, _("error reading inotify event")); } - ev = (struct inotify_event *) (evbuf + evbuf_off); + void_ev = evbuf + evbuf_off; + ev = void_ev; evbuf_off += sizeof (*ev) + ev->len; if (ev->len) /* event on ev->name in watched directory */ |