Rather than relying on code inspection to find places where signed ints would be erroneously promoted to unsigned, I went looking for a gcc option to automatically detect this. It's -Wsign-compare which is automatically included in -Wextra. Note it might be good to add to README-hacking to run configure with the CFLAGS="-Wall -Wextra" options?
So turning that on didn't show any more bugs, but I've attached a patch to fix the warnings in a couple of places where the code was ambiguous. There is still a warning given by the ST_BLKSIZE() macro in src/system.h where it compares a blksize_t which is long int on my system, to SIZE_MAX. Perhaps a cast to (size_t) is required there to confirm the intent? thanks, Pádraig.
>From 9af2fe570111c4073588293facdea87cf9151e55 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= <[EMAIL PROTECTED]> Date: Fri, 27 Jun 2008 08:38:42 +0100 Subject: [PATCH] truncate: Silence -Wsign-compare errors src/truncate.c: Cast signed to unsigned to confirm intent which will silence -Wsign-compare errors --- src/truncate.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/truncate.c b/src/truncate.c index 02d4102..fd321c6 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -189,9 +189,9 @@ do_ftruncate (int fd, char const *fname, off_t ssize, rel_mode_t rel_mode) } if (rel_mode == rm_min) - nsize = MAX (fsize, ssize); + nsize = MAX (fsize, (uintmax_t) ssize); else if (rel_mode == rm_max) - nsize = MIN (fsize, ssize); + nsize = MIN (fsize, (uintmax_t) ssize); else if (rel_mode == rm_rdn) /* 0..ssize-1 -> 0 */ nsize = (fsize / ssize) * ssize; -- 1.5.3.6
_______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils