• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ safe_realloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: mutt_ungetch

void mutt_ungetch (int ch, int op)
{
  event_t tmp;

  tmp.ch = ch;
  tmp.op = op;

  if (UngetCount >= UngetBufLen)
    safe_realloc ((void **) &KeyEvent, (UngetBufLen += 128) * sizeof(event_t));

  KeyEvent[UngetCount++] = tmp;
}
开发者ID:kbraga111,项目名称:muttassign6-ed.purp.only-,代码行数:12,代码来源:curs_lib.c


示例17: log_outputs

/* Transmutes the internal data buffer into the structured output
 * which may be retured to the client.
 */
int log_outputs(output_buffer *ob, unsigned int modelid) {
  unsigned int outputid, nquantities, dataid, quantityid;
  output_t *out;
  double *odata;

  unsigned int modelid_offset = ob->modelid_offset[modelid];
  unsigned int ndata = ob->count[modelid];
  output_buffer_data *buf = (output_buffer_data *)(ob->buffer + (modelid * BUFFER_LEN * collection_status.precision));
	     
  for (dataid = 0; dataid < ndata; ++dataid) {
    outputid = buf->outputid;
    assert(collection_status.num_outputs > outputid);

    nquantities = buf->num_quantities;
    assert(collection_status.output_num_quantities[outputid] == nquantities);

    if (outputid > collection_status.num_outputs) { return LOG_OUTPUTS_CORRUPT; }
    if (collection_status.output_num_quantities[outputid] != nquantities) { return LOG_OUTPUTS_CORRUPT; }
		 
    out = &output[(modelid_offset+modelid)*collection_status.num_outputs + outputid];
		 
    if (out->samples == out->allocated) {
      out->allocated *= 2;
      out->data = (double*)safe_realloc(out->data, nquantities * out->allocated * sizeof(double));
      if (!out->data)
	{ return LOG_OUTPUTS_OUT_OF_MEMORY; }
    }
		 
    odata = &out->data[out->samples * nquantities];
		 
    /* Copies each element individually for implicit type conversion from float of 'precision' to double. */
    if(collection_status.precision == 4){
      float *fquantities = (float*) buf->quantities;
      for (quantityid = 0; quantityid < nquantities; ++quantityid) {
	odata[quantityid] = fquantities[quantityid];
      }
      buf = (output_buffer_data *)(fquantities + nquantities);
    }
    else /* collection_status.precision == 8 */{
      double *dquantities = (double*) buf->quantities;
      for (quantityid = 0; quantityid < nquantities; ++quantityid) {
	odata[quantityid] = dquantities[quantityid];
      }
      buf = (output_buffer_data *)(dquantities + nquantities);
    }

    ++out->samples;
  }
  ob->available[modelid] = 0;
	     
  return LOG_OUTPUTS_OK;
}
开发者ID:joshuaecook,项目名称:simengine,代码行数:55,代码来源:readSimulationData.c


示例18: calibrate

/* 
 * -- calibrate
 * 
 * Calibrate the packet timestamps 
 *
 */
void 
calibrate(struct _snifferinfo * info)
{
    struct map_area_header * m = info->m; 
    clock_retimer_t ** cr = info->clock_retimers;	
    uint size = info->retimer_size; 
    uint num;
    uint calibrated; 

    logmsg(V_LOGSNIFFER, "Starting timer calibration\n");

    num = calibrated = 0;
    do {
	struct timeval now;
	uint s, t;

        while (m->k2u_cons >= m->k2u_prod)
            mb();
        t = m->k2u_prod;

        mb();
        gettimeofday(&now, NULL);
        for (s = m->k2u_cons; s < t; s++) {
            uint iface;
            int ind;

            ind = s % RING_SIZE;
            iface = m->k2u_pipe[ind].interface;
            if (iface == (unsigned short)-1)
                continue;

            if (iface >= size) {
                logmsg(V_LOGSNIFFER, 
		    "Extend retimer array: %d -> %d\n", size, iface + 1);
                cr = safe_realloc(cr, (iface + 1) * sizeof(cr[0]));
                memset(cr + size, 0, sizeof(cr[0]) * (iface + 1 - size));
                size = iface + 1;
            }

            if (cr[iface] == NULL) {
                logmsg(V_LOGSNIFFER, "Found interface %d\n", iface);
                cr[iface] = new_clock_retimer("", 0);
                num++;
            }
            calibrated += doTimer(cr[iface], m->k2u_pipe[ind].tstamp, 0, &now);
        }
        discard_packets(m);
    } while (calibrated != num);

    info->retimer_size = size; 
    logmsg(V_LOGSNIFFER, "Calibrated %d interfaces\n", calibrated);
}
开发者ID:JackieXie168,项目名称:como,代码行数:58,代码来源:sniffer-sk98.c


示例19: update_header_tags

static int update_header_tags(HEADER *h, notmuch_message_t *msg)
{
	struct nm_hdrdata *data = h->data;
	notmuch_tags_t *tags;
	char *tstr = NULL, *p;
	size_t sz = 0;

	dprint(2, (debugfile, "nm: tags update requested (%s)\n", h->env->message_id));

	for (tags = notmuch_message_get_tags(msg);
	     tags && notmuch_tags_valid(tags);
	     notmuch_tags_move_to_next(tags)) {

		const char *t = notmuch_tags_get(tags);
		size_t xsz = t ? strlen(t) : 0;

		if (!xsz)
			continue;

		if (NotmuchHiddenTags) {
			p = strstr(NotmuchHiddenTags, t);

			if (p && (p == NotmuchHiddenTags
				  || *(p - 1) == ','
				  || *(p - 1) == ' ')
			    && (*(p + xsz) == '\0'
				  || *(p + xsz) == ','
				  || *(p + xsz) == ' '))
				continue;
		}

		safe_realloc(&tstr, sz + (sz ? 1 : 0) + xsz + 1);
		p = tstr + sz;
		if (sz) {
			*p++ = ' ';
			sz++;
		}
		memcpy(p, t, xsz + 1);
		sz += xsz;
	}

	if (data->tags && tstr && strcmp(data->tags, tstr) == 0) {
		FREE(&tstr);
		dprint(2, (debugfile, "nm: tags unchanged\n"));
		return 1;
	}

	FREE(&data->tags);
	data->tags = tstr;
	dprint(2, (debugfile, "nm: new tags: '%s'\n", tstr));
	return 0;
}
开发者ID:kostaz,项目名称:mutt-kz,代码行数:52,代码来源:mutt_notmuch.c


示例20: mpg123_index

/* int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill) */
int attribute_align_arg mpg123_index(mpg123_handle *mh, long **offsets, long *step, size_t *fill)
{
	int err;
	size_t i;
	long smallstep;
	size_t thefill;
	off_t largestep;
	off_t *largeoffsets;
	struct wrap_data *whd;

	whd = wrap_get(mh);
	if(whd == NULL) return MPG123_ERR;

	err = MPG123_LARGENAME(mpg123_index)(mh, &largeoffsets, &largestep, &thefill);
	if(err != MPG123_OK) return err;

	/* For a _very_ large file, even the step could overflow. */
	smallstep = largestep;
	if(smallstep != largestep)
	{
		mh->err = MPG123_LFS_OVERFLOW;
		return MPG123_ERR;
	}
	if(step != NULL) *step = smallstep;

	/* When there are no values stored, there is no table content to take care of.
	   Table pointer does not matter. Mission completed. */
	if(thefill == 0) return MPG123_OK;

	if(fill != NULL) *fill = thefill;

	/* Construct a copy of the index to hand over to the small-minded client. */
	*offsets = safe_realloc(whd->indextable, (*fill)*sizeof(long));
	if(*offsets == NULL)
	{
		mh->err = MPG123_OUT_OF_MEM;
		return MPG123_ERR;
	}
	whd->indextable = *offsets;
	/* Elaborate conversion of each index value, with overflow check. */
	for(i=0; i<*fill; ++i)
	{
		whd->indextable[i] = largeoffsets[i];
		if(whd->indextable[i] != largeoffsets[i])
		{
			mh->err = MPG123_LFS_OVERFLOW;
			return MPG123_ERR;
		}
	}
	/* If we came that far... there should be a valid copy of the table now. */
	return MPG123_OK;
}
开发者ID:GYGit,项目名称:reactos,代码行数:53,代码来源:lfs_wrap.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ safe_snprintf函数代码示例发布时间:2022-05-30
下一篇:
C++ safe_read函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap