> Date: Tue, 8 Dec 2015 13:00:49 -0500
> From: Michael McConville <mm...@mykolab.com>
> 
> I thought I'd look for other examples after the grep fix.
> 
> ok?

It really is confusing to use off_t for something that's not a byte
offset.  If integer overflow really is an issue you care about, use
"long long".

Note that on many non-BSD systems off_t is still a 32-bit integer, at
least by default.  So using off_t doesn't help portability.  Search
the interwebs for "Large File Summit" for the full horror story!

> Index: csplit.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/csplit/csplit.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 csplit.c
> --- csplit.c  11 Oct 2015 17:43:03 -0000      1.8
> +++ csplit.c  8 Dec 2015 17:57:50 -0000
> @@ -80,7 +80,7 @@ int  kflag;                 /* Keep output if error oc
>  /*
>   * Other miscellaneous globals (XXX too many)
>   */
> -long  lineno;                /* Current line number in input file */
> +off_t         lineno;                /* Current line number in input file */
>  long  reps;                  /* Number of repetitions for this pattern */
>  long  nfiles;                /* Number of files output so far */
>  long  maxfiles;              /* Maximum number of files we can create */
> @@ -439,7 +439,7 @@ do_rexp(const char *expr)
>  void
>  do_lineno(const char *expr)
>  {
> -     long lastline, tgtline;
> +     off_t lastline, tgtline;
>       char *ep, *p;
>       FILE *ofp;
>  
> @@ -455,7 +455,8 @@ do_lineno(const char *expr)
>               ofp = newfile();
>               while (lineno + 1 != lastline) {
>                       if ((p = get_line()) == NULL)
> -                             errx(1, "%ld: out of range", lastline);
> +                             errx(1, "%lld: out of range",
> +                                 (long long)lastline);
>                       if (fputs(p, ofp) != 0)
>                               break;
>               }
> 
> 

Reply via email to