On 2015-09-19 20:29, Michael McConville wrote:
> Index: locate/fastfind.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/locate/locate/fastfind.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 fastfind.c
> --- locate/fastfind.c 16 Jan 2015 06:40:09 -0000      1.12
> +++ locate/fastfind.c 19 Sep 2015 18:28:30 -0000
> @@ -65,7 +65,8 @@ statistic (fp, path_fcodes)
>               } else
>                       count += c - OFFSET;
>  
> -             sane_count(count);
> +             if (count < 0 || count >= PATH_MAX)
> +                     errx(1, "corrupted database");
>               for (p = path + count; (c = getc(fp)) > SWITCH; size++)
>                       if (c < PARITY) {
>                               if (c == UMLAUT) {
> @@ -212,7 +213,8 @@ fastfind
>                       count += c - OFFSET;
>               }
>  
> -             sane_count(count);
> +             if (count < 0 || count >= PATH_MAX)
> +                     errx(1, "corrupted database");
>               /* overlay old path */
>               p = path + count;
>               foundchar = p - 1;
> Index: locate/locate.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/locate/locate/locate.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 locate.c
> --- locate/locate.c   16 Jan 2015 06:40:09 -0000      1.26
> +++ locate/locate.c   19 Sep 2015 18:28:30 -0000
> @@ -331,15 +331,6 @@ usage(void)
>       exit(1);
>  }
>  
> -void
> -sane_count(int count)
> -{
> -     if (count < 0 || count >= PATH_MAX) {
> -             fprintf(stderr, "locate: corrupted database\n");
> -             exit(1);
> -     }
> -}
> -
>  /* load fastfind functions */
>  
>  /* statistic */

What's your thinking behind this? To me this seems like a perfectly
rational and well motivated function to have, both for readability and
rather than having to repeat the same statements several times over in
the rest of the code, risking future calamity if a change is made in one
place and not the other...

I mean, I don't know if I'm unusual, but I often find myself breaking
out separate functions from larger pieces of code, that may end up being
called just that one time in a program, just to improve readability and
keep things logically apart.


Regards,
/Benny

Reply via email to