The base/count bounds checking was insufficient, leading to a kernel memory
[dragonfly.git] / contrib / gperf / src / bool-array.icc
1 /* Inline Functions for bool-array.{h,cc}.
2
3    Copyright (C) 1989-1998 Free Software Foundation, Inc.
4    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
5
6 This file is part of GNU GPERF.
7
8 GNU GPERF is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
11 any later version.
12
13 GNU GPERF is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU GPERF; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 // This needs:
23 //#include <stdio.h>
24 //#include <string.h>
25 //#include "options.h"
26 //#include "trace.h"
27
28 INLINE
29 Bool_Array::Bool_Array (void)
30 {
31   T (Trace t ("Bool_Array::Bool_Array");)
32   storage_array = 0;
33   iteration_number = size = 0;
34 }
35
36 INLINE void
37 Bool_Array::init (STORAGE_TYPE *buffer, unsigned int s)
38 {
39   T (Trace t ("Bool_Array::init");)
40   size             = s;
41   iteration_number = 1;
42   storage_array    = buffer;
43   memset (storage_array, 0, s * sizeof (*storage_array));
44   if (option[DEBUG])
45     fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
46              size, (unsigned int) (size * sizeof (*storage_array)));
47 }
48
49 INLINE int
50 Bool_Array::find (int index)
51 {
52   T (Trace t ("Bool_Array::find");)
53   if (storage_array[index] == iteration_number)
54     return 1;
55   else
56     {
57       storage_array[index] = iteration_number;
58       return 0;
59     }
60 }
61
62 INLINE void
63 Bool_Array::reset (void)
64 {
65   T (Trace t ("Bool_Array::reset");)
66   /* If we wrap around it's time to zero things out again!  However, this only
67      occurs once about every 2^31 or 2^15 iterations, so it should probably
68      never happen! */
69
70   if (++iteration_number == 0)
71     {
72       if (option[DEBUG])
73         {
74           fprintf (stderr, "(re-initializing bool_array)...");
75           fflush (stderr);
76         }
77       iteration_number = 1;
78       memset (storage_array, 0, size * sizeof (*storage_array));
79       if (option[DEBUG])
80         {
81           fprintf (stderr, "done\n");
82           fflush (stderr);
83         }
84     }
85 }