当前位置: 首页>>代码示例>>C++>>正文


C++ safe_realloc函数代码示例

本文整理汇总了C++中safe_realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_realloc函数的具体用法?C++ safe_realloc怎么用?C++ safe_realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safe_realloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: findVFile

/*
** Find a VFile by name.  Create it if it does not already exist and
** initialize it to the size and content given.
**
** Return NULL only if the filesystem is full.
*/
static VFile *createVFile(const char *zName, int sz, unsigned char *pData){
  VFile *pNew = findVFile(zName);
  int i;
  if( pNew ) return pNew;
  for(i=0; i<MX_FILE && g.aFile[i].sz>=0; i++){}
  if( i>=MX_FILE ) return 0;
  pNew = &g.aFile[i];
  if( zName ){
    pNew->zFilename = safe_realloc(0, strlen(zName)+1);
    memcpy(pNew->zFilename, zName, strlen(zName)+1);
  }else{
    pNew->zFilename = 0;
  }
  pNew->nRef = 0;
  pNew->sz = sz;
  pNew->a = safe_realloc(0, sz);
  if( sz>0 ) memcpy(pNew->a, pData, sz);
  return pNew;
}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:25,代码来源:fuzzcheck.c

示例2: rule_inst_table_resize

/*
 * Check whether there's room for one more clause in rule_inst_table.
 * - if not, make the table larger
 */
void rule_inst_table_resize(rule_inst_table_t *rule_inst_table){
	int32_t size = rule_inst_table->size;
	int32_t num_rinsts = rule_inst_table->num_rule_insts;
	if (num_rinsts + 1 < size) return;
	if (MAXSIZE(sizeof(rule_inst_t *), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	rule_inst_table->rule_insts = (rule_inst_t **) safe_realloc(
			rule_inst_table->rule_insts, size * sizeof(rule_inst_t *));
	rule_inst_table->assignment = (samp_truth_value_t *) safe_realloc(
			rule_inst_table->assignment, size * sizeof(samp_truth_value_t));
	rule_inst_table->rule_watched = (samp_clause_list_t *) safe_realloc(
			rule_inst_table->rule_watched, size * sizeof(samp_clause_list_t));
	rule_inst_table->size = size; 
	//if (MAXSIZE(sizeof(samp_clause_t *), sizeof(rule_inst_t)) < num_clauses) {
	//	out_of_memory();
	//}
}
开发者ID:pombreda,项目名称:pce,代码行数:23,代码来源:tables.c

示例3: array_remove_i

static int array_remove_i(struct array *a,int fr) {
  if(!a->n) { return 0; }
  a->n--;
  if(fr && a->freev)
    a->freev(a->e[a->n],a->freevp);
  if(a->n*4 < a->N && a->N>=16) {
    a->N /= 2;
    a->e = safe_realloc(a->e,sizeof(void*)*a->N);
  }
  return 1;
}
开发者ID:ens-ds23,项目名称:fuse8,代码行数:11,代码来源:array.c

示例4: extend_ptr_heap

/*
 * Increate the heap size by 50%
 */
static void extend_ptr_heap(ptr_heap_t *heap) {
  uint32_t n;

  n = heap->size + 1;
  n += n>>1;
  if (n >= MAX_PTR_HEAP_SIZE) {
    out_of_memory();
  }
  heap->heap = (void **) safe_realloc(heap->heap, n * sizeof(void *));
  heap->size = n;
}
开发者ID:polazarus,项目名称:ocamlyices2,代码行数:14,代码来源:ptr_heap.c

示例5: local_retune

void
local_retune(MHEGBackend *t, OctetString *service)
{
	unsigned int service_id;
	char service_str[64];
	char *slash;
	int prefix_len;

	/* assert */
	if(service->size < 6 || strncmp((char *) service->data, "dvb://", 6) != 0)
		fatal("local_retune: unable to tune to '%.*s'", service->size, service->data);

	/* extract the service_id */
	service_id = si_get_service_id(service);
	snprintf(service_str, sizeof(service_str), "%u", service_id);

	/*
	 * base_dir is: [path/to/services/]<service_id>
	 * so we just need to replace the last filename component with the new service_id
	 */
	slash = strrchr(t->base_dir, '/');
	if(slash == NULL)
	{
		/* no preceeding path */
		t->base_dir = safe_realloc(t->base_dir, strlen(service_str) + 1);
		strcpy(t->base_dir, service_str);
	}
	else
	{
		prefix_len = (slash - t->base_dir) + 1;
		t->base_dir = safe_realloc(t->base_dir, prefix_len + strlen(service_str) + 1);
		strcpy(t->base_dir + prefix_len, service_str);
	}

	/* update rec://svc/def */
	local_set_service_url(t);

	verbose("Retune: new service gateway is '%s'", t->base_dir);

	return;
}
开发者ID:nexgenta,项目名称:redbutton,代码行数:41,代码来源:MHEGBackend.c

示例6: get_data

/* The expected input file is the result of anathons analysis */
int get_data(char *inFileName, Dat *dat){

	FILE *inFile = 0; /* input file */
	char line[80]; /* line */
	unsigned int allocated = 64; /* allocation counter */
    pcre *re; /* regular expression */
    const char *error; /* error message string */
	int erroffset; /* error offset */
    int ovector[OVECCOUNT]; /* match vector */
    int rc; /* match return value */
    char **substring_list; /* substring list */

	/* initialise/allocate memory for set of (64) frag entries */
    dat->nData = 0;
	dat->data = safe_malloc(allocated * sizeof(Ang));

	/* read data */
	inFile = safe_open(inFileName, "r");

	/* compile regexp */
    re = pcre_compile("^.{7}\t.{4}\t.{6}\t(........)\t(........)\t(........)", 0, &error, &erroffset, NULL);

    /* count the number of models */
    while(fgets(line, 80, inFile) != NULL )
    {
        rc = pcre_exec(re, NULL, line, strlen(line), 0, 0, ovector, OVECCOUNT);
        if (rc == 4){
            pcre_get_substring_list(line, ovector, rc, (const char ***)&substring_list);
            dat->data[dat->nData].phi1   = atof(substring_list[1]);
            dat->data[dat->nData].phi2   = atof(substring_list[2]);
            dat->data[dat->nData].theta  = atof(substring_list[3]);
            ++dat->nData;

            /* free substring_list memory */
            pcre_free_substring_list((const char **)substring_list);
        }

		/* allocate more memory if needed */
		if (dat->nData == allocated) {
			allocated += 64;
			dat->data = safe_realloc(dat->data, allocated * sizeof(Ang));
		}
    }

	/* free regexp */
    pcre_free(re);

	assert(dat->nData > 1);

    /* close file handle */
	fclose(inFile);
	return 0;
}
开发者ID:jkleinj,项目名称:OPTICS,代码行数:54,代码来源:dist_ang.c

示例7: heap_grow

static int heap_grow(gh_heap_t *heap) {
  int newsize;

  /* Do we really need to grow? */
  assert(heap->count == heap->highwm);

  newsize = heap->count + GH_SLOTS;
  heap->slots = (gh_hnode_t **)safe_realloc(heap->slots,
                                            newsize * sizeof(gh_hnode_t *));
  heap->highwm += GH_SLOTS;
  return 0;
}
开发者ID:ParrotSec,项目名称:nmap,代码行数:12,代码来源:gh_heap.c

示例8: append_str_item

static void append_str_item(char **str, const char *item, int sep)
{
    char *p;
    size_t sz = strlen(item);
    size_t ssz = *str ? strlen(*str) : 0;

    safe_realloc(str, ssz + (ssz && sep ? 1 : 0) + sz + 1);
    p = *str + ssz;
    if (sep && ssz)
        *p++ = sep;
    memcpy(p, item, sz + 1);
}
开发者ID:ceyusa,项目名称:mutt-kz,代码行数:12,代码来源:mutt_notmuch.c

示例9: extend_map

/*
 * Make map 50% larger
 */
static void extend_map(map_t *map) {
  uint32_t n;

  n = map->size + 1;
  n += n>>1;
  if (n >= MAX_MAP_SIZE) {
    out_of_memory();
  }

  map->data = (map_elem_t *) safe_realloc(map->data, n * sizeof(map_elem_t));
  map->size = n;
}
开发者ID:polazarus,项目名称:ocamlyices2,代码行数:15,代码来源:fun_maps.c

示例10: query_instance_table_resize

void query_instance_table_resize(query_instance_table_t *table) {
	int32_t size = table->size;
	int32_t num_queries = table->num_queries;
	if (num_queries + 1 < size) return;
	if (MAXSIZE(sizeof(samp_query_instance_t *), 0) - size <= (size/2)) {
		out_of_memory();
	}
	size += size/2;
	table->query_inst = (samp_query_instance_t **)
		safe_realloc(table->query_inst, size * sizeof(samp_query_instance_t *));
	table->size = size; 
}
开发者ID:pombreda,项目名称:pce,代码行数:12,代码来源:tables.c

示例11: pred_tbl_resize

static void pred_tbl_resize(pred_tbl_t *pred_tbl){//call this extend, not resize
	int32_t size = pred_tbl->size;
	int32_t num_preds = pred_tbl->num_preds;
	if (num_preds < size) return;
	if (MAXSIZE(sizeof(pred_entry_t), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	pred_tbl->entries = (pred_entry_t *) safe_realloc(pred_tbl->entries,
			size * sizeof(pred_entry_t));
	pred_tbl->size = size; 
}
开发者ID:pombreda,项目名称:pce,代码行数:12,代码来源:tables.c

示例12: safe_realloc

MemBlock BigHeap::resizeBig(void* ptr, size_t newsize) {
  // Since we don't know how big it is (i.e. how much data we should memcpy),
  // we have no choice but to ask malloc to realloc for us.
  auto const n = static_cast<BigNode*>(ptr) - 1;
  auto const newNode = static_cast<BigNode*>(
    safe_realloc(n, newsize + sizeof(BigNode))
  );
  if (newNode != n) {
    m_bigs[newNode->index] = newNode;
  }
  return {newNode + 1, newsize};
}
开发者ID:carriercomm,项目名称:hhvm,代码行数:12,代码来源:memory-manager.cpp

示例13: source_table_extend

void source_table_extend(source_table_t *table) {
	int32_t size = table->size;
	int32_t num_entries = table->num_entries;
	if (num_entries + 1 < size) return;
	if (MAXSIZE(sizeof(source_entry_t *), 0) - size <= (size/2)) {
		out_of_memory();
	}
	size += size/2;
	table->entry = (source_entry_t **)
		safe_realloc(table->entry, size * sizeof(source_entry_t *));
	table->size = size; 
}
开发者ID:pombreda,项目名称:pce,代码行数:12,代码来源:tables.c

示例14: mix_add_entry

static void mix_add_entry (REMAILER ***type2_list, REMAILER *entry,
			   size_t *slots, size_t *used)
{
  if (*used == *slots)
  {
    *slots += 5;
    safe_realloc (type2_list, sizeof (REMAILER *) * (*slots));
  }
  
  (*type2_list)[(*used)++] = entry;
  if (entry) entry->num = *used;
}
开发者ID:aschrab,项目名称:mutt,代码行数:12,代码来源:remailer.c

示例15: safe_malloc

/* Read a line from ``fp'' into the dynamically allocated ``s'',
 * increasing ``s'' if necessary. The ending "\n" or "\r\n" is removed.
 * If a line ends with "\", this char and the linefeed is removed,
 * and the next line is read too.
 */
char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line)
{
  size_t offset = 0;
  char *ch;

  if (!s)
  {
    s = safe_malloc (STRING);
    *size = STRING;
  }

  FOREVER
  {
    if (fgets (s + offset, *size - offset, fp) == NULL)
    {
      safe_free (&s);
      return NULL;
    }
    if ((ch = strchr (s + offset, '\n')) != NULL)
    {
      (*line)++;
      *ch = 0;
      if (ch > s && *(ch - 1) == '\r')
	*--ch = 0;
      if (ch == s || *(ch - 1) != '\\')
	return s;
      offset = ch - s - 1;
    }
    else
    {
      int c;
      c = getc (fp); /* This is kind of a hack. We want to know if the
                        char at the current point in the input stream is EOF.
                        feof() will only tell us if we've already hit EOF, not
                        if the next character is EOF. So, we need to read in
                        the next character and manually check if it is EOF. */
      if (c == EOF)
      {
        /* The last line of fp isn't \n terminated */
        (*line)++;
        return s;
      }
      else
      {
        ungetc (c, fp); /* undo our dammage */
        /* There wasn't room for the line -- increase ``s'' */
        offset = *size - 1; /* overwrite the terminating 0 */
        *size += STRING;
        safe_realloc (&s, *size);
      }
    }
  }
}
开发者ID:bluviolin,项目名称:pgpanalysis,代码行数:58,代码来源:lib.c


注:本文中的safe_realloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。