Sender: rich AT phekda DOT freeserve DOT co DOT uk Message-ID: <3B6BC349.946B4D25@phekda.freeserve.co.uk> Date: Sat, 04 Aug 2001 10:41:29 +0100 From: Richard Dawe X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586) X-Accept-Language: de,fr MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: ls bug References: <200107121836 DOT UAA09468 AT father DOT ludd DOT luth DOT se> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hello. I finally got round to look at this - sorry for the delay. Martin Str|mberg wrote: > > According to Eli Zaretskii: > > I'd begin by making sure that the reason is indeed the fact that > > st_size is signed; what I said was just a hunch. [snip] > > If the answer is YES, then the change should be probably done in `ls'. > > If not... well, we need another hunch. 'ls' casts st_size to an unsigned type - uintmax_t - which is defined to be unsigned long long: if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode)) sprintf (p, "%3u, %3u ", (unsigned) major (f->stat.st_rdev), (unsigned) minor (f->stat.st_rdev)); else { char hbuf[LONGEST_HUMAN_READABLE + 1]; sprintf (p, "%8s ", human_readable ((uintmax_t) f->stat.st_size, hbuf, 1, output_block_size < 0 ? output_block_size : 1)); } This cast does not work. This seems strange - I would expect a cast from signed long to unsigned long long to work. Wouldn't the value be zero-extended to fill the unsigned long long? Does anyone have any suggestions on how I can fix this? (I don't have any of my C reference material here.) Typecasting to unsigned long then uintmax_t seems to work, but I think that's a hack rather than the solution. (I thought it might be a compiler bug at first - the same thing happens with gcc 2.95.2, 2.95.3, 3.0.) If I edit config.h to define uintmax_t to be unsigned long, then 'ls' shows the right length. But that might have other side effects. Bye, Rich =] -- Richard Dawe http://www.phekda.freeserve.co.uk/richdawe/