pike.git / src / post_modules / CritBit / inttree.cmod

version» Context lines:

pike.git/src/post_modules/CritBit/inttree.cmod:1: + /* -*- c -*- + || This file is part of Pike. For copyright information see COPYRIGHT. + || Pike is distributed under GPL, LGPL and MPL. See the file COPYING + || for more information. + */ +    /* vim:syntax=c    */   #include "common.h"      #include "critbit/int2svalue.h"   #define CB_PRINT_KEY(buf, key) do \    { string_builder_sprintf((buf), "%"PRINTPIKEINT"d", CB_UINT2INT((key).str)); } while(0)   #define CB_LOW_ASSIGN_SVALUE_KEY(key, s) do { \    struct svalue * __ = (s); \    SET_SVAL(*__, PIKE_T_INT, 0, integer, CB_UINT2INT((key).str)); \
pike.git/src/post_modules/CritBit/inttree.cmod:53:    key.len.bits = 0;       if (s->size_shift || s->len > 18) Pike_error("Malformed ip.\n");       switch (sscanf((char *)STR0(s), "%3u.%3u.%3u.%3u/%2u", &a, &b, &c, &d, &e))    {    case 5:    if (e > 32) Pike_error("Mask is too big!");    key.len.chars = 0;    key.len.bits = WASTED_BITS + e; +  /* FALLTHRU */    case 4:    if (a > 255 || b > 255 || c > 255 || d > 255)    Pike_error("Bad ip.\n");    key.str = (INT_TYPE)(a << 24 | b << 16 | c << 8 | d);    break;    default:    Pike_error("Malformed ip.\n");    }       return key;   }      struct pike_string * cb_ptype_from_key_ipv4(cb_key key) {    char buf[19];    size_t len;       unsigned INT32 ip = (unsigned INT32)key.str;    -  if (key.len.bits || !key.len.chars) { +  if (!key.len.chars) { +  if (key.len.bits > WASTED_BITS)    ip &= (~0U) << (32 - (int)(key.len.bits - WASTED_BITS));    len = snprintf(buf, 19, "%u.%u.%u.%u/%u",    (unsigned int)(ip>>24), (unsigned int)((ip>>16)&0xff),    (unsigned int)((ip>>8)&0xff), (unsigned int)(ip&0xff),    (unsigned int)(key.len.bits - WASTED_BITS));    } else {    len = snprintf(buf, 19, "%u.%u.%u.%u",    (unsigned int)(ip>>24), (unsigned int)((ip>>16)&0xff),    (unsigned int)((ip>>8)&0xff), (unsigned int)(ip&0xff));    }
pike.git/src/post_modules/CritBit/inttree.cmod:132:   #undef THIS   #define THIS THIS_IPV4TREE   #cmod_include "prefix.H"   #cmod_include "tree_source.H"       PIKEFUN int mask(int n) {    RETURN MASK(INT_TYPE, n);    }       PIKEFUN int umask(int n) { -  RETURN MASK(unsigned INT64, n); +  RETURN MASK(UINT64, n);    }       PIKEFUN int cmp_key(mixed a, mixed b) {    cb_key k1 = CB_KEY_FROM_SVALUE(a);    cb_key k2 = CB_KEY_FROM_SVALUE(b);    INT_TYPE ret;    if (CB_KEY_LT(k1, k2)) {    ret = -1;    } else if (CB_KEY_MATCH(k1, k2)) {    ret = 0;