示例#1
0
int ltbl_add (lookup_table *table, int key) {
  ltbl_check (table);

  assert (table->size > 0);

  int x;
  if ( (x = ltbl_get_to (table, key)) ) {
    return x;
  }

  if (table->currId >= table->size) {
    assert (table->currId == table->size);

    int len = table->size;

    table->size = table->currId * 2;
    table->rev = qrealloc (table->rev, sizeof (int) * table->size, sizeof (int) * len);
//    fprintf (stderr, "realloc done\n");
    assert (table->rev != NULL);
    assert (0 < table->size && table->size < 100000000);
    table->hash = poly_h (table->rev, table->size);
    memset (table->rev + len, 0, sizeof (int) * (table->size - len));
  }
  assert (table->currId < table->size);

  table->rev[table->currId] = key;
  //htbl_add (&(table->to), key, table->currId);
  *(htbl_find_or_create (&(table->to), key)) = table->currId;

  return table->currId++;
}
示例#2
0
static void add_mapping(size_t offset, size_t size, uint64 ea)
{
  fmap = (mapping_t *)qrealloc(fmap, (nmap+1)*sizeof(mapping_t));
  if ( fmap == NULL ) errnomem();
  fmap[nmap].offset = (uint32)offset;
  fmap[nmap].size   = (uint32)size;
  fmap[nmap].ea     = ea;
  nmap++;
}
示例#3
0
static void add_mapping(ulong offset, ulong size, uint64 ea)
{
  map = (mapping_t *)qrealloc(map, (nmap+1)*sizeof(mapping_t));
  if ( map == NULL ) errnomem();
  map[nmap].offset = offset;
  map[nmap].size   = size;
  map[nmap].ea     = ea;
  nmap++;
}
示例#4
0
void
add_class(struct RP_class *root, ea_t adr, size_t namelen)
{
  if ( root->total == root->alloced )
   root->children = 
     (struct RP_class **)qrealloc(root->children,
       sizeof(struct RP_class *) * (root->alloced += RP_INCREMENT));
  root->children[root->total++] = alloc_class(adr, namelen, root);
  if ( namelen > max_size )
   max_size = namelen;
}
示例#5
0
int Buffer::check_size(uint32_t max) {
    if (max <= sz) return 0;
    max = (max + BLOCK_SIZE) & ~(BLOCK_SIZE - 1);   //round up to next BLOCK_SIZE
    unsigned char *tmp = (unsigned char *)qrealloc(bptr, max);
    if (tmp) {
        bptr = tmp;
        sz = max;
        return 0;
    }
    error = true;
    return 1;
}
示例#6
0
文件: reg.cpp 项目: nealey/vera
static void add_mapping(ea_t from, ea_t to)
{
  deb(IDA_DEBUG_IDP, "add_mapping %a -> %a\n", from, to);
  if ( (nummaps % MAP_CHUNK) == 0 )
  {
    map = (portmap_t *)qrealloc(map, (nummaps+MAP_CHUNK)*sizeof(portmap_t));
    if ( map == NULL ) nomem("add_mapping");
  }
  map[nummaps].from = from;
  map[nummaps].to   = to;
  nummaps++;
}
示例#7
0
文件: qepoll.c 项目: DiaosiDev/qnode
static int
epoll_expand(qengine_t *engine) {
  qepoll_t *epoll;
  void    *data;

  epoll = (qepoll_t*)engine->data;
  data  = qrealloc(epoll->events, sizeof(struct epoll_event) * engine->size);
  if (data == NULL) {
    return QERROR;
  }
  epoll->events = data;

  return QOK;
}
示例#8
0
文件: qkqueue.c 项目: DiaosiDev/qnode
static int
kqueue_expand(qengine_t *engine) {
  qkqueue_t *kqueue;
  void      *data;

  kqueue = engine->data;
  data  = qrealloc(kqueue->events, sizeof(struct kevent) * engine->size);
  if (data == NULL) {
    return QERROR;
  }
  kqueue->events = data;

  return QOK;
}
示例#9
0
static int
minheap_reserve(qminheap_t* heap, unsigned int size) {
  void **data;

  if (heap->size >= size) {
    return 0;
  }
  size = heap->size + 128;
  data = qrealloc(heap->data, sizeof(void*) * size);
  if (data == NULL) {
    return -1;
  }

  heap->data = data;
  heap->size = size;

  return 0;
}
示例#10
0
文件: qstring.c 项目: chinnurtb/qnode
static qstr_header_t*
reserve(qstr_header_t *header, size_t len) {
  size_t          new_len;
  qstr_header_t  *new_header;

  if (header->free > len) {
    return header;
  }

  new_len = header->len + len;
  new_header  = qrealloc(header, sizeof(qstr_header_t) + new_len + 1);
  if (new_header == NULL) {
    return NULL;
  }
  new_header->free = len;

  return new_header;
}
示例#11
0
文件: batch.c 项目: husthl/qos
static bool batch_auto_grow_up( int id ){
    uverify( id_valid( id ) );

    batch_t* const batch = (batch_t*)id;

    const int len = batch->len;
    const int increase_len = 50;
    const int new_len = len + increase_len;

    callback_arg_t* const new_list = qrealloc( batch->list, new_len * sizeof( callback_arg_t ) );
    // 如果没有足够的空间,老空间没有释放,仍然存在。简单返回false,说明grow_up失败。
    return_false_if( NULL == new_list );
    batch->list = new_list;
    // 老空间内容,已经拷贝在前面,只用初始化后面一段即可。
    return_false_if( !init_list( batch->list + len, increase_len ) );

    batch->len = new_len;

    uverify( id_valid( id ) );
    return true;
}
示例#12
0
文件: sig.cpp 项目: filcab/patchdiff2
int dline_add(dline_t * dl, ea_t ea, char options)
{
	char buf[256];
	char tmp[256];
	char dis[256];
	char addr[30];
	char * dll;
	int len;
	flags_t f;

	buf[0] = '\0';

	f = getFlags(ea);
	generate_disasm_line(ea, dis, sizeof(dis));

	decode_insn(ea);
	init_output_buffer(buf, sizeof(buf));

	// Adds block label
	if (has_dummy_name(f))
	{
		get_nice_colored_name(ea,tmp,sizeof(tmp),GNCN_NOSEG|GNCN_NOFUNC);
		out_snprintf("%s", tmp);
		out_line(":\n", COLOR_DATNAME);
	}

	if (options)
	{
		qsnprintf(addr, sizeof(addr), "%a", ea);
		out_snprintf("%s ", addr);
	}

	out_insert(get_output_ptr(), dis);
	term_output_buffer();

	len = strlen(buf);

	if (dl->available < (len+3))
	{
		dll = (char *)qrealloc(dl->lines, sizeof(char*) * (dl->num+len+256));
		if (!dll) return -1;

		dl->available = len+256;
		dl->lines = dll;
	}

	if (dl->num)
	{
		dl->lines[dl->num] = '\n';
		dl->num++;
	}

	memcpy(&dl->lines[dl->num], buf, len);

	dl->available -= len+1;
	dl->num += len;

	dl->lines[dl->num] = '\0';

	return 0;
}