Ejemplo n.º 1
0
	// DebugAllocator::_do_check
	size_t DebugAllocator::_do_check( void * i_address ) const
	{
		MEMO_ASSERT( i_address != nullptr ); // i_address can't be null

		void * const block = address_sub( i_address, m_heading_nomansland_size );

		size_t size = 0;

		if( m_heading_nomansland_size >= sizeof( void * ) )
		{
			_check_nomansland( block, m_heading_nomansland_size - sizeof( void * ), 
				address_add( i_address, sizeof( void * ) ) );

			void * user_block_end = _invert_address( *reinterpret_cast< void * * >( block ) );
			size = address_diff( user_block_end, i_address );

			_check_nomansland( user_block_end, m_tailing_nomansland_size, i_address );
		}
		else
		{
			_check_nomansland( block, m_heading_nomansland_size, i_address );
		}

		return size;
	}
Ejemplo n.º 2
0
void address_sort(struct address *z,unsigned int n)
{
    unsigned int i;
    unsigned int j;
    unsigned int p;
    unsigned int q;
    struct address t;

    i = j = n;
    --z;

    while (j > 1) {
        if (i > 1) {
            --i;
            t = z[i];
        }
        else {
            t = z[j];
            z[j] = z[i];
            --j;
        }
        q = i;
        while ((p = q * 2) < j) {
            if (address_diff(&z[p + 1],&z[p]) >= 0) ++p;
            z[q] = z[p];
            q = p;
        }
        if (p == j) {
            z[q] = z[p];
            q = p;
        }
        while ((q > i) && (address_diff(&t,&z[p = q/2]) > 0)) {
            z[q] = z[p];
            q = p;
        }
        z[q] = t;
    }
}
Ejemplo n.º 3
0
main()
{
    struct address t;
    int i;
    int j;
    int k;
    char ch;

    umask(022);

    if (!address_alloc_readyplus(&x,0)) nomem();

    fd = open_read("data");
    if (fd == -1) strerr_die2sys(111,FATAL,"unable to open data: ");
    buffer_init(&b,read,fd,bspace,sizeof bspace);

    fdcdb = open_trunc("data.tmp");
    if (fdcdb == -1) die_datatmp();
    if (cdb_make_start(&cdb,fdcdb) == -1) die_datatmp();

    while (match) {
        ++linenum;
        if (getln(&b,&line,&match,'\n') == -1)
            strerr_die2sys(111,FATAL,"unable to read line: ");

        while (line.len) {
            ch = line.s[line.len - 1];
            if ((ch != ' ') && (ch != '\t') && (ch != '\n')) break;
            --line.len;
        }
        if (!line.len) continue;

        j = 1;
        for (i = 0; i < NUMFIELDS; ++i) {
            if (j >= line.len) {
                if (!stralloc_copys(&f[i],"")) nomem();
            }
            else {
                k = byte_chr(line.s + j,line.len - j,':');
                if (!stralloc_copyb(&f[i],line.s + j,k)) nomem();
                j += k + 1;
            }
        }

        switch(line.s[0]) {
        default:
            syntaxerror(": unrecognized leading character");
        case '#':
            break;
        case '-':
            break;
        case '+':
            byte_zero(&t,sizeof t);
            if (!dns_domain_fromdot(&t.name,f[0].s,f[0].len)) nomem();
            t.namelen = dns_domain_length(t.name);
            case_lowerb(t.name,t.namelen);
            if (!stralloc_0(&f[1])) nomem();
            if (!ip4_scan(f[1].s,t.ip)) syntaxerror(": malformed IP address");
            if (!stralloc_0(&f[2])) nomem();
            if (!stralloc_0(&f[2])) nomem();
            byte_copy(t.location,2,f[2].s);
            if (!address_alloc_append(&x,&t)) nomem();
            break;
        case '%':
            if (!stralloc_0(&f[0])) nomem();
            if (!stralloc_0(&f[0])) nomem();
            if (!stralloc_copyb(&result,f[0].s,2)) nomem();
            if (!stralloc_0(&f[1])) nomem();
            if (!stralloc_copys(&key,"%")) nomem();
            ipprefix_cat(&key,f[1].s);
            if (cdb_make_add(&cdb,key.s,key.len,result.s,result.len) == -1)
                die_datatmp();
            break;
        }
    }

    close(fd);
    address_sort(x.s,x.len);

    i = 0;
    while (i < x.len) {
        for (j = i + 1; j < x.len; ++j)
            if (address_diff(x.s + i,x.s + j))
                break;
        if (!stralloc_copys(&key,"+")) nomem();
        if (!stralloc_catb(&key,x.s[i].location,2)) nomem();
        if (!stralloc_catb(&key,x.s[i].name,x.s[i].namelen)) nomem();
        if (!stralloc_copys(&result,"")) nomem();
        while (i < j)
            if (!stralloc_catb(&result,x.s[i++].ip,4)) nomem();
        if (cdb_make_add(&cdb,key.s,key.len,result.s,result.len) == -1)
            die_datatmp();
    }

    if (cdb_make_finish(&cdb) == -1) die_datatmp();
    if (fsync(fdcdb) == -1) die_datatmp();
    if (close(fdcdb) == -1) die_datatmp(); /* NFS stupidity */
    if (rename("data.tmp","data.cdb") == -1)
        strerr_die2sys(111,FATAL,"unable to move data.tmp to data.cdb: ");

    _exit(0);
}