bin/107824: /usr/bin/head does not work with files over 2GB.

Brooks Davis brooks at one-eyed-alien.net
Thu Jan 11 08:50:21 PST 2007


The following reply was made to PR bin/107824; it has been noted by GNATS.

From: Brooks Davis <brooks at one-eyed-alien.net>
To: Brian Cornell <briancornell at earthlink.net>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: bin/107824: /usr/bin/head does not work with files over 2GB.
Date: Thu, 11 Jan 2007 10:03:37 -0600

 On Thu, Jan 11, 2007 at 02:19:04PM +0000, Brian Cornell wrote:
 > 
 > Change byte counters in head.c from long to double types.  This has been tested & works.
 > Output of diff from release to modified source code:
 > diff head.c head.61freebsd
 > 64c64
 > < static void head_bytes(FILE *, double);
 > ---
 > > static void head_bytes(FILE *, size_t);
 > 73,74c73
 > <       int first, linecnt = -1, eval = 0;
 > <       double bytecnt = -1;
 > ---
 > >       int first, linecnt = -1, bytecnt = -1, eval = 0;
 > 81c80
 > <                       bytecnt = strtod(optarg, &ep);
 > ---
 > >                       bytecnt = strtol(optarg, &ep, 10);
 > 142c141
 > < head_bytes(FILE *fp, double cnt)
 > ---
 > > head_bytes(FILE *fp, size_t cnt)
 > 145c144
 > <       double readlen;
 > ---
 > >       size_t readlen;
 
 This is bogus.  Using a floating point type to hold an interger quantity
 is wrong.  The correct type here is off_t.  I'd suggest using strtoll or
 strtonum for the conversion.
 
 -- Brooks


More information about the freebsd-bugs mailing list