r23792: convert Samba4 to GPLv3
[sfrench/samba-autobuild/.git] / source4 / lib / util / idtree.c
index d29c3b8fbdc307d354599e1f4d9bf0586fbc06c5..1e2cc2976a330a6f371c748e8913e7d7408a7668 100644 (file)
@@ -12,7 +12,7 @@
     
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -21,8 +21,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -37,7 +36,9 @@
 
 #define IDR_BITS 5
 #define IDR_FULL 0xfffffffful
+#if 0 /* unused */
 #define TOP_LEVEL_FULL (IDR_FULL >> 30)
+#endif
 #define IDR_SIZE (1 << IDR_BITS)
 #define IDR_MASK ((1 << IDR_BITS)-1)
 #define MAX_ID_SHIFT (sizeof(int)*8 - 1)
@@ -107,6 +108,8 @@ static int sub_alloc(struct idr_context *idp, void *ptr, int *starting_id)
        int l, id;
        uint32_t bm;
 
+       memset(pa, 0, sizeof(pa));
+
        id = *starting_id;
        p = idp->top;
        l = idp->layers;
@@ -271,7 +274,7 @@ static void *_idr_find(struct idr_context *idp, int id)
        /* Mask off upper bits we don't use for the search. */
        id &= MAX_ID_MASK;
 
-       while (n > 0 && p) {
+       while (n >= IDR_BITS && p) {
                n -= IDR_BITS;
                p = p->ary[(id >> n) & IDR_MASK];
        }