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

C++ safemalloc函数代码示例

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

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



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

示例1: safemalloc

ASetRootConfig *CreateASetRootConfig ()
{
	ASetRootConfig *config =
			(ASetRootConfig *) safemalloc (sizeof (ASetRootConfig));

	/* let's initialize ASetRoot config with some nice values: */
	config->my_backs = NULL;
	config->my_desks = NULL;
	config->style_defs = NULL;

	config->more_stuff = NULL;

	return config;
}
开发者ID:Remmy,项目名称:afterstep,代码行数:14,代码来源:ASetRoot.c


示例2: while

void
vc1::es_parser_c::add_bytes(unsigned char *buffer,
                            int size) {
  memory_slice_cursor_c cursor;

  int previous_pos            = -1;
  int64_t previous_stream_pos = m_stream_pos;

  if (m_unparsed_buffer.is_set() && (0 != m_unparsed_buffer->get_size()))
    cursor.add_slice(m_unparsed_buffer);
  cursor.add_slice(buffer, size);

  if (3 <= cursor.get_remaining_size()) {
    uint32_t marker = (1 << 24) | ((unsigned int)cursor.get_char() << 16) | ((unsigned int)cursor.get_char() << 8) | (unsigned int)cursor.get_char();

    while (1) {
      if (vc1::is_marker(marker)) {
        if (-1 != previous_pos) {
          int new_size = cursor.get_position() - 4 - previous_pos;

          memory_cptr packet(new memory_c(safemalloc(new_size), new_size, true));
          cursor.copy(packet->get_buffer(), previous_pos, new_size);

          handle_packet(packet);
        }

        previous_pos = cursor.get_position() - 4;
        m_stream_pos = previous_stream_pos + previous_pos;
      }

      if (!cursor.char_available())
        break;

      marker <<= 8;
      marker  |= (unsigned int)cursor.get_char();
    }
  }

  if (-1 == previous_pos)
    previous_pos = 0;

  int new_size = cursor.get_size() - previous_pos;
  if (0 != new_size) {
    memory_cptr new_unparsed_buffer = memory_c::alloc(new_size);
    cursor.copy(new_unparsed_buffer->get_buffer(), previous_pos, new_size);
    m_unparsed_buffer = new_unparsed_buffer;

  } else
    m_unparsed_buffer = memory_cptr(NULL);
}
开发者ID:Trottel,项目名称:mkvtoolnix,代码行数:50,代码来源:vc1.cpp


示例3: list_restack

void list_restack(unsigned long *body, unsigned long length)
{
  PagerWindow *t;
  Window target_w;
  Window *wins;
  int i, j, d;

  wins = (Window *) safemalloc (length * sizeof (Window));
  /* first restack in the icon view */
  j = 0;
  for (i = 0; i < (length - FvwmPacketHeaderSize); i += 3)
  {
    target_w = body[i];
    t = Start;
    while((t!= NULL)&&(t->w != target_w))
    {
      t = t->next;
    }
    if (t != NULL)
    {
      wins[j++] = t->IconView;
    }
  }
  XRestackWindows(dpy, wins, j);

  /* now restack each desk separately, since they have separate roots */
  for (d = 0; d < ndesks; d++)
  {
    j = 0;
    for (i = 0; i < (length - 4); i+=3)
    {
      target_w = body[i];
      t = Start;
      while((t!= NULL)&&((t->w != target_w)||(t->desk != d+desk1)))
      {
	t = t->next;
      }
      if (t != NULL)
      {
	if (t->PagerView != None)
	{
	  wins[j++] = t->PagerView;
	}
      }
    }
    XRestackWindows(dpy, wins, j);
  }
  free (wins);
}
开发者ID:att,项目名称:uwin,代码行数:49,代码来源:FvwmPager.c


示例4: main

/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
void main(int argc, char **argv)
{
  char *temp, *s;
  char *display_name = NULL;

  /* Record the program name for error messages */
  temp = argv[0];

  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;

  MyName = safemalloc(strlen(temp)+2);
  strcpy(MyName,"*");
  strcat(MyName, temp);

  if((argc != 6)&&(argc != 7))
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      PACKAGE_VERSION);
      exit(1);
    }

  /* Open the X display */
  if (!(dpy = XOpenDisplay(display_name))) 
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  screen= DefaultScreen(dpy);
  ScreenHeight = DisplayHeight(dpy,screen);
  ScreenWidth = DisplayWidth(dpy,screen);

  /* We should exit if our fvwm pipes die */
  signal (SIGPIPE, DeadPipe);  
  
  fd[0] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);

  fd_width = GetFdWidth();

  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);

  Loop(fd);
}
开发者ID:tonnerre,项目名称:fvwm,代码行数:55,代码来源:FvwmSave.c


示例5: assert

void *safegrowarray(void *ptr, size_t *allocated, size_t eltsize,
                    size_t oldlen, size_t extralen, bool secret)
{
    /* The largest value we can safely multiply by eltsize */
    assert(eltsize > 0);
    size_t maxsize = (~(size_t)0) / eltsize;

    size_t oldsize = *allocated;

    /* Range-check the input values */
    assert(oldsize <= maxsize);
    assert(oldlen <= maxsize);
    assert(extralen <= maxsize - oldlen);

    /* If the size is already enough, don't bother doing anything! */
    if (oldsize > oldlen + extralen)
        return ptr;

    /* Find out how much we need to grow the array by. */
    size_t increment = (oldlen + extralen) - oldsize;

    /* Invent a new size. We want to grow the array by at least
     * 'increment' elements; by at least a fixed number of bytes (to
     * get things started when sizes are small); and by some constant
     * factor of its old size (to avoid repeated calls to this
     * function taking quadratic time overall). */
    if (increment < 256 / eltsize)
        increment = 256 / eltsize;
    if (increment < oldsize / 16)
        increment = oldsize / 16;

    /* But we also can't grow beyond maxsize. */
    size_t maxincr = maxsize - oldsize;
    if (increment > maxincr)
        increment = maxincr;

    size_t newsize = oldsize + increment;
    void *toret;
    if (secret) {
        toret = safemalloc(newsize, eltsize);
        memcpy(toret, ptr, oldsize * eltsize);
        smemclr(ptr, oldsize * eltsize);
        sfree(ptr);
    } else {
        toret = saferealloc(ptr, newsize, eltsize);
    }
    *allocated = newsize;
    return toret;
}
开发者ID:NaldoDj,项目名称:VeraCrypt,代码行数:49,代码来源:memory.c


示例6: AddToQueue

void AddToQueue(int module, unsigned long *ptr, int size, int done)
{
  struct queue_buff_struct *c, *e;
  unsigned long *d;

  c =
      (struct queue_buff_struct *)
      safemalloc(sizeof(struct queue_buff_struct));
  c->next = NULL;
  c->size = size;
  c->done = done;
  d = (unsigned long *) safemalloc(size);
  c->data = d;
  memcpy(d, ptr, size);

  e = pipeQueue[module];
  if (e == NULL) {
    pipeQueue[module] = c;
    return;
  }
  while (e->next != NULL)
    e = e->next;
  e->next = c;
}
开发者ID:rn10950,项目名称:FVWM95-Updated,代码行数:24,代码来源:module.c


示例7: make_kde_config_group_tag

static xml_elem_t*
make_kde_config_group_tag( const char *name ) 
{
	xml_elem_t *group = NULL ; 
	int name_len = 0 ; 
	if( name ) 
		while( name[name_len] != ']' && name[name_len] != '\0' && name[name_len] != '\n') ++name_len;
	KDE_CONFIG_MAKE_TAG(group);
	if( name_len > 0 ) 
	{	
		group->parm = safemalloc( 4+1+1+name_len+1+1 );
		sprintf( group->parm, "name=\"%*.*s\"", name_len, name_len, name );
	} 		                   /* WE ALLOW SECTIONS WITH NO NAMES */
	return group;
}	   
开发者ID:Vaevictusnet,项目名称:afterstep-devel,代码行数:15,代码来源:kde.c


示例8: size

MPEGFrame::MPEGFrame(binary *n_data, uint32_t n_size, bool n_bCopy):
  size(n_size), bCopy(n_bCopy) {

  if(bCopy) {
    data = (binary *)safemalloc(size);
    memcpy(data, n_data, size);
  } else {
    data = n_data;
  }
  invisible      = false;
  firstRef       = -1;
  secondRef      = -1;
  seqHdrData     = NULL;
  seqHdrDataSize = 0;
}
开发者ID:Trottel,项目名称:mkvtoolnix,代码行数:15,代码来源:M2VParser.cpp


示例9: str_AllocateCopy

static char* str_AllocateCopy(const char *src)
{
  u32 len=0;
  if(src!=NULL) len=strlen(src);
  
  char *ptag=(char*)safemalloc(len+1);
  
  for(u32 idx=0;idx<len;idx++){
    ptag[idx]=src[idx];
  }
  
  ptag[len]=(char)0;
  
  return(ptag);
}
开发者ID:Mbmax,项目名称:ismart-kernel,代码行数:15,代码来源:lang.cpp


示例10: send_image_path

static void send_image_path(fmodule *module)
{
	char *msg;
	char *ImagePath = PictureGetImagePath();

	if (ImagePath && *ImagePath != 0)
	{
		msg = safemalloc(strlen(ImagePath) + 12);
		sprintf(msg, "ImagePath %s\n", ImagePath);
		SendName(module, M_CONFIG_INFO, 0, 0, 0, msg);
		free(msg);
	}

	return;
}
开发者ID:ThomasAdam,项目名称:fvwm-cvs,代码行数:15,代码来源:modconf.c


示例11: countmalloc

void         *
countmalloc (const char *fname, int line, size_t length)
{
	void         *ptr;
    if( (int)length < 0 )
	{
		fprintf( stderr, "too large malloc of %lu from %s:%d\n", (unsigned long)length, fname, line );
#ifdef DEBUG_ALLOC_STRICT
{	char *segv = NULL ;	*segv = 0 ;  }
#endif
	}
	ptr = safemalloc (length);
	count_alloc (fname, line, ptr, length, C_MEM | C_MALLOC);
	return ptr;
}
开发者ID:Remmy,项目名称:afterstep,代码行数:15,代码来源:audit.c


示例12: add_map_to_gw

/**
 * Add a mapping (local port -> remote host + port) to the gateway structure.
 *
 * Creates a listening port for the local side and adds the fd to the fd_map
 * on the gateway that maps listening ports to the map structure.
 *
 * The mappings are stored in an array of pointers gw->pm that is grown
 * appropriately and gw->n_maps stores the size of this array.
 *
 * @gw			gateway structure to add to
 * @local_port	the local port to listen on -- bound to localhost:NNNN
 * @host		the remote host to tunnel to
 * @remote_port	the port on the remote side to connect to
 * @return		Nothing, if anything fails here the program exits
 */
void add_map_to_gw(struct gw_host *gw,
				  uint32_t local_port,
				  char *host,
				  uint32_t remote_port)
{
	struct static_port_map *spm;

	debug("Adding map %d %s:%d to %s", local_port, host, remote_port, gw->name);

	spm = safemalloc(sizeof(struct static_port_map), "static_port_map alloc");
	spm->parent = gw;
	spm->local_port = local_port;
	spm->remote_host = safestrdup(host, "spm strdup hostname");
	spm->remote_port = remote_port;
	spm->ch = safemalloc(sizeof(struct chan_sock *), "spm->ch");

	spm->listen_fd = create_listen_socket(local_port, "localhost");
	add_fdmap(gw->listen_fdmap, spm->listen_fd, spm);
	spm->parent = gw;
	spm->n_channels = 0;

	saferealloc((void **)&gw->pm, (gw->n_maps + 1) * sizeof(spm), "gw->pm realloc");
	gw->pm[gw->n_maps++] = spm;
}
开发者ID:fubarwrangler,项目名称:autotun,代码行数:39,代码来源:port_map.c


示例13: unique_filename

static char *
unique_filename(char *path, char *prefix, int *pFd)
{
	char *tempFile;

	tempFile = (char *)safemalloc(strlen(path) + strlen(prefix) + 8);
	sprintf(tempFile, "%s/%sXXXXXX", path, prefix);
	*pFd =  fvwm_mkstemp(tempFile);
	if (*pFd == -1)
	{
		free(tempFile);
		tempFile = NULL;
	}
	return tempFile;
}
开发者ID:krazeivan,项目名称:fvwm,代码行数:15,代码来源:fsm.c


示例14: assert

static char *get_string_arg (const char *line, regmatch_t * match)
{
        char *p;
        const unsigned int len = match->rm_eo - match->rm_so;

        assert (line);
        assert (len > 0);

        p = (char *) safemalloc (len + 1);
        if (!p)
                return NULL;

        memcpy (p, line + match->rm_so, len);
        p[len] = '\0';
        return p;
}
开发者ID:ScratchesTheItch,项目名称:ScoreboardRaspberryPiCode_Configs,代码行数:16,代码来源:conf.c


示例15: collect_gradient_offsets_str

static Bool 
collect_gradient_offsets_str(void *data, void *aux_data)
{
	ASGradientPoint *point = (ASGradientPoint*)data; 
 	char **pstr =  (char**) aux_data ;
	if( *pstr )
	{
		*pstr = realloc( *pstr, strlen(*pstr)+6 );
		sprintf( *pstr, "%s %2.2f", *pstr, point->offset ); 
	}else
	{	
		*pstr = safemalloc(6);
		sprintf( *pstr, "%2.2f", point->offset ); 
	}
	return True;	
}	 
开发者ID:Vaevictusnet,项目名称:afterstep-devel,代码行数:16,代码来源:asgtkgradient.c


示例16: hstore

bool
hstore(HASH *tb, char *key, STR *val)
{
    char *s;
    int i;
    int hash;
    HENT *entry;
    HENT **oentry;

    if (!tb)
	return FALSE;
    for (s=key,		i=0,	hash = 0;
      /* while */ *s;
	 s++,		i++,	hash *= 5) {
	hash += *s * coeff[i];
    }

    oentry = &(tb->tbl_array[hash & tb->tbl_max]);
    i = 1;

    for (entry = *oentry; entry; i=0, entry = entry->hent_next) {
	if (entry->hent_hash != hash)		/* strings can't be equal */
	    continue;
	if (strNE(entry->hent_key,key))	/* is this it? */
	    continue;
	/*NOSTRICT*/
	safefree(entry->hent_val);
	entry->hent_val = val;
	return TRUE;
    }
    /*NOSTRICT*/
    entry = (HENT*) safemalloc(sizeof(HENT));

    entry->hent_key = savestr(key);
    entry->hent_val = val;
    entry->hent_hash = hash;
    entry->hent_next = *oentry;
    *oentry = entry;

    if (i) {				/* initial entry? */
	tb->tbl_fill++;
	if ((tb->tbl_fill * 100 / (tb->tbl_max + 1)) > FILLPCT)
	    hsplit(tb);
    }

    return FALSE;
}
开发者ID:eserte,项目名称:app-a2p,代码行数:47,代码来源:hash.c


示例17: pull_client_data

/*
 * pull_client_data is used to pull across any client data (like in a
 * POST) which needs to be handled before an error can be reported, or
 * server headers can be processed.
 *	- rjkaes
 */
static int
pull_client_data(struct conn_s *connptr, long int length)
{
	char *buffer;
	ssize_t len;

	buffer = safemalloc(min(MAXBUFFSIZE, length));
	if (!buffer)
		return -1;

	do {
		len = safe_read(connptr->client_fd, buffer,
				min(MAXBUFFSIZE, length));
		if (len <= 0)
			goto ERROR_EXIT;

		if (!connptr->error_variables) {
			if (safe_write(connptr->server_fd, buffer, len) < 0)
				goto ERROR_EXIT;
		}

		length -= len;
	} while (length > 0);

	/*
	 * BUG FIX: Internet Explorer will leave two bytes (carriage
	 * return and line feed) at the end of a POST message.  These
	 * need to be eaten for tinyproxy to work correctly.
	 */
	socket_nonblocking(connptr->client_fd);
	len = recv(connptr->client_fd, buffer, 2, MSG_PEEK);
	socket_blocking(connptr->client_fd);

	if (len < 0 && errno != EAGAIN)
		goto ERROR_EXIT;

	if (len == 2 && CHECK_CRLF(buffer, len))
		read(connptr->client_fd, buffer, 2);

	safefree(buffer);
	return 0;

  ERROR_EXIT:
	safefree(buffer);
	return -1;
}
开发者ID:OPSF,项目名称:uClinux,代码行数:52,代码来源:reqs.c


示例18: build_url

/*
 * Build a URL from parts.
 */
static int
build_url(char **url, const char *host, int port, const char *path)
{
	int len;

	assert(url != NULL);
	assert(host != NULL);
	assert(port > 0 && port < 32768);
	assert(path != NULL);

	len = strlen(host) + strlen(path) + 14;
	*url = safemalloc(len);
	if (*url == NULL)
		return -1;

	return snprintf(*url, len, "http://%s:%d%s", host, port, path);
}
开发者ID:OPSF,项目名称:uClinux,代码行数:20,代码来源:reqs.c


示例19: setErrMsg

/* keep this simple for now, don't count % tokens, etc */
char *
setErrMsg ( char ** gErrMsg, int count, ... )
{
int i;
int argLength = 1, length;
char * strings[5];

	va_list ap;
	va_start ( ap, count );

	for ( i = 0; i < count; i++ ) {
		strings[i] =  va_arg ( ap, char* );
		argLength += strlen ( strings[i] );
	}

	va_end ( ap );

	if ( *gErrMsg )
	  free ( *gErrMsg );

	*gErrMsg = (char *)safemalloc ( argLength * sizeof (char) );

	switch ( count ) {
		case 1:
			strcpy ( *gErrMsg, strings[0] );
			break;
		case 2:
			sprintf ( *gErrMsg, strings[0], strings[1] );
			break;
		case 3:
			sprintf ( *gErrMsg, strings[0], strings[1], strings[2] );
			break;
		case 4:
			sprintf ( *gErrMsg, strings[0], strings[1], strings[2], strings[3] );
			break;
		case 5:
			sprintf ( *gErrMsg, strings[0], strings[1], strings[2], strings[3], strings[4] );
			break;
	}

	// sv_setpv ( perl_get_sv("!",0), gErrMsg );
	sv_setpv ( perl_get_sv("@",0), *gErrMsg );

	return ( *gErrMsg );

}
开发者ID:gitpan,项目名称:Aw,代码行数:47,代码来源:Util.c


示例20: make_absolute

char         *
make_absolute (const char *path1, const char *path2)
{
	char         *path;

	if( path1 == NULL || path2 == NULL )
		return mystrdup("./") ;
	if (*path2 == '/' || *path2 == '~' || *path2 == '$')
		path = copy_replace_envvar(path2);
	else
		/* relative path */
	{
		path = safemalloc (strlen ((char*)path1) + strlen ((char*)path2) + 2);
		sprintf (path, "%s/%s", path1, path2);
	}
	return path;
}
开发者ID:Vaevictusnet,项目名称:afterstep-devel,代码行数:17,代码来源:dirtree.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ safestrcpy函数代码示例发布时间:2022-05-30
下一篇:
C++ safef函数代码示例发布时间: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