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


C++ safemalloc函数代码示例

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


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


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