diff --git a/src/backend.cmod b/src/backend.cmod index 587890f601dfce67b1d5b4ff0e842681e6fdb53d..e525016c2bb688a8ab194d2f83b9a0b0f083d0f4 100644 --- a/src/backend.cmod +++ b/src/backend.cmod @@ -238,8 +238,7 @@ static void low_set_backend_for_fd(int fd, struct Backend_struct *b) fd_map = (struct Backend_struct **) realloc(fd_map, sizeof(struct Backend_struct *) * fd_map_size); } else { - fd_map = (struct Backend_struct **) - malloc(sizeof(struct Backend_struct *) * fd_map_size); + fd_map = calloc(sizeof(struct Backend_struct *), fd_map_size); } if(!fd_map) Pike_fatal("Out of memory in backend:low_set_backend_for_fd.\n" @@ -725,20 +724,14 @@ PIKECLASS Backend { if (!me->call_heap) { me->call_heap_size = 128; - me->call_heap = - (struct Backend_CallOut_struct **) - xalloc(sizeof(struct Backend_CallOut_struct *) * - me->call_heap_size); - MEMSET(me->call_heap, 0, sizeof(struct Backend_CallOut_struct *) * - me->call_heap_size); + me->call_heap = xcalloc(sizeof(struct Backend_CallOut_struct *), + me->call_heap_size); me->num_pending_calls = 0; } if (!me->call_hash) { me->hash_size = hashprimes[me->hash_order]; - me->call_hash = - (struct hash_ent *)xalloc(sizeof(struct hash_ent)*me->hash_size); - MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); + me->call_hash = xcalloc(sizeof(struct hash_ent),me->hash_size); } }else{ struct hash_ent *new_hash; @@ -754,13 +747,12 @@ PIKECLASS Backend me->call_heap_size *= 2; me->call_heap = new_heap; - if((new_hash=(struct hash_ent *)malloc(sizeof(struct hash_ent)* - hashprimes[me->hash_order+1]))) + if((new_hash=calloc(sizeof(struct hash_ent), + hashprimes[me->hash_order+1]))) { free(me->call_hash); me->call_hash = new_hash; me->hash_size = hashprimes[++me->hash_order]; - MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); /* Re-hash */ for(e=0;e<me->num_pending_calls;e++) diff --git a/src/modules/Image/colortable.c b/src/modules/Image/colortable.c index d04c98e4aec0d883eadbf77d0a6952079f4a272f..9237efef67591bce9d9fc696f0f453c28ffa5f37 100644 --- a/src/modules/Image/colortable.c +++ b/src/modules/Image/colortable.c @@ -3971,8 +3971,8 @@ static int* ordered_calculate_errors(int dxs,int dys) int xf,yf; int x,y; - src=malloc(sizeof(int)*dxs*dys); - dest=malloc(sizeof(int)*dxs*dys); + src=calloc(sizeof(int),dxs*dys); + dest=calloc(sizeof(int),dxs*dys); if (!src||!dest) { @@ -3983,8 +3983,6 @@ static int* ordered_calculate_errors(int dxs,int dys) *src=0; sxs=sys=1; - MEMSET(src,0,sizeof(int)*dxs*dys); - MEMSET(dest,0,sizeof(int)*dxs*dys); for (;;) { diff --git a/src/modules/Image/encodings/_xpm.c b/src/modules/Image/encodings/_xpm.c index efab3610023eb41acc4da7df26d84a748cf2bdd9..13b3cbc62dc9422b42a587c5f19c9cc5418e0467 100644 --- a/src/modules/Image/encodings/_xpm.c +++ b/src/modules/Image/encodings/_xpm.c @@ -320,8 +320,7 @@ void f__xpm_write_rows( INT32 args ) { rgba_group **p_colors; int i; - p_colors = (rgba_group **)xalloc(sizeof(rgba_group *)*65536); - MEMSET(p_colors, 0, sizeof(rgba_group *)*65536); + p_colors = xcalloc(sizeof(rgba_group *), 65536); for(i=0; i<colors->size; i++) { struct pike_string *c = colors->item[i].u.string; @@ -329,8 +328,7 @@ void f__xpm_write_rows( INT32 args ) unsigned short id = extract_short((unsigned char *)c->str); if(!p_colors[id]) { - p_colors[id] = (rgba_group *)xalloc(sizeof(rgba_group)*128); - MEMSET(p_colors[id],0,sizeof(rgba_group)*128); + p_colors[id] = xcalloc(sizeof(rgba_group), 128); } if(ind > 127) { diff --git a/src/modules/Image/encodings/wbf.c b/src/modules/Image/encodings/wbf.c index ba69a269103a8bc9bc92288575ec7be72d5579c6..05e389ff0268811bdff7e3fa2cb39782f88358d3 100644 --- a/src/modules/Image/encodings/wbf.c +++ b/src/modules/Image/encodings/wbf.c @@ -143,8 +143,7 @@ static struct wbf_header decode_header( struct buffer *data ) { struct ext_header *eh; q = read_uchar( data ); - eh = xalloc( sizeof( struct ext_header ) ); - MEMSET( eh, 0, sizeof( struct ext_header ) ); + eh = xcalloc( 1, sizeof( struct ext_header ) ); eh->next = res.first_ext_header; res.first_ext_header = eh; eh->name_len = ((q>>4) & 0x7) + 1; @@ -361,8 +360,7 @@ static void push_wap_type0_image_data( struct image *i ) int x, y; unsigned char *data, *p; rgb_group *is; - data = xalloc( i->ysize * (i->xsize+7)/8 ); - MEMSET( data, 0, i->ysize * (i->xsize+7)/8 ); + data = xcalloc( i->ysize, (i->xsize+7)/8 ); is = i->img; for( y = 0; y<i->ysize; y++ ) { diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c index b6f4b9076deed81d17b19248972b4383233083bb..350aa4d79033a0a3af042386a78b8165aa4ee5b6 100644 --- a/src/modules/Image/image.c +++ b/src/modules/Image/image.c @@ -3725,15 +3725,14 @@ static void _image_outline(INT32 args,int mask) img=(struct image*)(o->storage); img->rgb=THIS->rgb; - tmp=malloc((THIS->xsize+width)*(THIS->ysize+height+1)); + tmp=calloc((THIS->xsize+width),(THIS->ysize+height+1)); if (!tmp) { free_object(o); if (matrix!=defaultmatrix) free(matrix); SIMPLE_OUT_OF_MEMORY_ERROR("outline", (THIS->xsize+width)*(THIS->ysize+height)+1); } - MEMSET(tmp,0,(THIS->xsize+width)*(THIS->ysize+height)); - + s=THIS->img; if (!mask) diff --git a/src/modules/Math/matrix_code.h b/src/modules/Math/matrix_code.h index 3dea0d6de9c9de6b369d19ded70bc03146188174..2ffa188fec8f988d30a326a909e0d9e9516fd0d2 100644 --- a/src/modules/Math/matrix_code.h +++ b/src/modules/Math/matrix_code.h @@ -152,11 +152,8 @@ static void matrixX(_create)(INT32 args) if ((THIS->ysize=ys=Pike_sp[1-args].u.integer)<=0) SIMPLE_BAD_ARG_ERROR(PNAME,2,"int > 0"); - THIS->m=m=malloc(sizeof(FTYPE)*xs*ys); - if (!m) - SIMPLE_OUT_OF_MEMORY_ERROR(PNAME, - sizeof(FTYPE)*xs*ys); - + THIS->m=m=xcalloc(sizeof(FTYPE),xs*ys); + if (args>2) { if (TYPEOF(Pike_sp[2-args]) == T_INT) z=(FTYPE)Pike_sp[2-args].u.integer; @@ -167,7 +164,6 @@ static void matrixX(_create)(INT32 args) if (Pike_sp[2-args].u.string==s__clr) { /* internal call: don't care */ - MEMSET(m,0,xs*ys*sizeof(FTYPE)); goto done_made; } else if (Pike_sp[2-args].u.string==s_identity) diff --git a/src/modules/_WhiteFish/blob.c b/src/modules/_WhiteFish/blob.c index a131720a78f85103c3c8589645de8f5cacc49ff4..bd246c0c48c73f7da40c68bf0677b40f87a7e0ec 100644 --- a/src/modules/_WhiteFish/blob.c +++ b/src/modules/_WhiteFish/blob.c @@ -155,8 +155,7 @@ int wf_blob_docid( Blob *b ) Blob *wf_blob_new( struct svalue *feed, struct pike_string *word ) { - Blob *b = malloc( sizeof( Blob ) ); - MEMSET(b, 0, sizeof(Blob) ); + Blob *b = calloc( 1, sizeof( Blob ) ); b->word = word; if( word ) add_ref(word); diff --git a/src/modules/_WhiteFish/buffer.c b/src/modules/_WhiteFish/buffer.c index 388177c2bb8d19f03195475b4c41df530215d4e7..ecf6cda8a94ad59b6391d265a954cab10e1ee9b3 100644 --- a/src/modules/_WhiteFish/buffer.c +++ b/src/modules/_WhiteFish/buffer.c @@ -201,9 +201,7 @@ void wf_buffer_set_pike_string( struct buffer *b, struct buffer *wf_buffer_new( ) { - struct buffer *b = xalloc( sizeof( struct buffer ) ); - MEMSET( b, 0, sizeof(struct buffer) ); - return b; + return xcalloc( 1, sizeof( struct buffer ) ); } void wf_buffer_append( struct buffer *b, diff --git a/src/modules/_WhiteFish/whitefish.c b/src/modules/_WhiteFish/whitefish.c index 087f11488eada6b0cd8286dc60d14dc0fbb3c3ad..0f020a4ebdb4cb73ded08f5f12e2df4c8dc0a73d 100644 --- a/src/modules/_WhiteFish/whitefish.c +++ b/src/modules/_WhiteFish/whitefish.c @@ -77,15 +77,13 @@ static void handle_hit( Blob **blobs, int cutoff ) { int i, j, k, end = 0; - Hit *hits = malloc( nblobs * sizeof(Hit) ); + Hit *hits = calloc( nblobs, sizeof(Hit) ); unsigned char *nhits = malloc( nblobs ); unsigned char *pos = malloc( nblobs ); int matrix[65][8]; MEMSET(matrix, 0, sizeof(matrix) ); - MEMSET(hits, 0, nblobs * sizeof(Hit) ); - MEMSET(pos, 0, nblobs ); for( i = 0; i<nblobs; i++ ) nhits[i] = wf_blob_nhits( blobs[i] ); diff --git a/src/pike_types.c b/src/pike_types.c index 16f33ac048f9752859ba7b3bd54797c24dfa10ad..944d235bb9a617f30b7f49c8469b8afe7c961bce 100644 --- a/src/pike_types.c +++ b/src/pike_types.c @@ -8680,9 +8680,8 @@ static struct callback *pike_type_gc_callback = NULL; void init_types(void) { /* Initialize hashtable here. */ - pike_type_hash = (struct pike_type **)xalloc(sizeof(struct pike_type *) * - (PIKE_TYPE_HASH_SIZE+1)); - MEMSET(pike_type_hash, 0, sizeof(struct pike_type *) * (PIKE_TYPE_HASH_SIZE+1)); + pike_type_hash = xcalloc(sizeof(struct pike_type *), + (PIKE_TYPE_HASH_SIZE+1)); pike_type_hash_size = PIKE_TYPE_HASH_SIZE; int_type_string = CONSTTYPE(tInt); /* MUST come before string! */ diff --git a/src/post_modules/Shuffler/a_source_pikestring.c b/src/post_modules/Shuffler/a_source_pikestring.c index 985fdc7f927e83cfdd8fe084ee29f4706d37d07c..f9e670cd31be09a3ccea13ba9d7afc7840138342 100644 --- a/src/post_modules/Shuffler/a_source_pikestring.c +++ b/src/post_modules/Shuffler/a_source_pikestring.c @@ -60,10 +60,10 @@ struct source *source_pikestring_make( struct svalue *s, if( TYPEOF(*s) != PIKE_T_STRING ) return 0; if( s->u.string->size_shift ) return 0; - res = malloc( sizeof( struct ps_source ) ); + res = calloc( 1, sizeof( struct ps_source ) ); + if( !res ) retrun NULL; debug_malloc_touch( res ); debug_malloc_touch( s ); - MEMSET( res, 0, sizeof( struct ps_source ) ); res->s.free_source = free_source; res->s.get_data = get_data; diff --git a/src/post_modules/Shuffler/a_source_system_memory.c b/src/post_modules/Shuffler/a_source_system_memory.c index c03b3119994e4af2041b5cd427f0b27c8ed696da..497e7875ea97e1dce816a5b507f0b15e80e390d1 100644 --- a/src/post_modules/Shuffler/a_source_system_memory.c +++ b/src/post_modules/Shuffler/a_source_system_memory.c @@ -78,8 +78,8 @@ struct source *source_system_memory_make( struct svalue *s, pop_stack(); } - res = malloc( sizeof( struct sm_source ) ); - MEMSET( res, 0, sizeof( struct sm_source ) ); + res = calloc( 1, sizeof( struct sm_source ) ); + if( !res ) return NULL; if( !(res->mem = (void*)get_storage( s->u.object, shm_program ) ) ) { diff --git a/src/post_modules/Shuffler/b_source_normal_file.c b/src/post_modules/Shuffler/b_source_normal_file.c index 6348e3c66815adab9dddee6d97be66d7707120e9..9b3399b12b7c78f739ff1184c72e629d28fd475c 100644 --- a/src/post_modules/Shuffler/b_source_normal_file.c +++ b/src/post_modules/Shuffler/b_source_normal_file.c @@ -96,8 +96,8 @@ struct source *source_normal_file_make( struct svalue *s, if (find_identifier("query_fd", s->u.object->prog) < 0) return 0; - res = malloc( sizeof( struct fd_source ) ); - MEMSET( res, 0, sizeof( struct fd_source ) ); + res = calloc( 1, sizeof( struct fd_source ) ); + if( !res ) return NULL; apply( s->u.object, "query_fd", 0 ); res->fd = Pike_sp[-1].u.integer; diff --git a/src/post_modules/Shuffler/c_source_stream.c b/src/post_modules/Shuffler/c_source_stream.c index 5c97b060bf245cced9b92619c021539e53057c21..e0359cd8647125489a05626464f7df7a5de6692e 100644 --- a/src/post_modules/Shuffler/c_source_stream.c +++ b/src/post_modules/Shuffler/c_source_stream.c @@ -167,9 +167,8 @@ struct source *source_stream_make( struct svalue *s, if (find_identifier("query_fd", s->u.object->prog) < 0) return 0; - res = malloc( sizeof( struct fd_source ) ); + res = calloc( 1, sizeof( struct fd_source ) ); if (!res) return NULL; - MEMSET( res, 0, sizeof( struct fd_source ) ); apply( s->u.object, "query_fd", 0 ); res->fd = Pike_sp[-1].u.integer; diff --git a/src/post_modules/Shuffler/d_source_pikestream.c b/src/post_modules/Shuffler/d_source_pikestream.c index 358b2b287d22bf1319e39c81cbd89959025697cd..e5a666b8bacb5424dfb8e234d53a90bc2439d4c4 100644 --- a/src/post_modules/Shuffler/d_source_pikestream.c +++ b/src/post_modules/Shuffler/d_source_pikestream.c @@ -170,8 +170,8 @@ struct source *source_pikestream_make( struct svalue *s, (find_identifier("set_read_callback",s->u.object->prog)==-1) ) return 0; - res = malloc( sizeof( struct pf_source ) ); - MEMSET( res, 0, sizeof( struct pf_source ) ); + res = calloc( 1, sizeof( struct pf_source ) ); + if( !res ) return NULL; res->len = len; res->skip = start; diff --git a/src/post_modules/Shuffler/e_source_block_pikestream.c b/src/post_modules/Shuffler/e_source_block_pikestream.c index c709a68e0f486406de0219cbcfe295f35e771010..0c386b93b2e5178601233280f843ab1499f650f1 100644 --- a/src/post_modules/Shuffler/e_source_block_pikestream.c +++ b/src/post_modules/Shuffler/e_source_block_pikestream.c @@ -86,8 +86,8 @@ struct source *source_block_pikestream_make( struct svalue *s, (find_identifier("read",s->u.object->prog)==-1) ) return 0; - res = malloc( sizeof( struct pf_source ) ); - MEMSET( res, 0, sizeof( struct pf_source ) ); + res = calloc( 1, sizeof( struct pf_source ) ); + if( !res ) return NULL; res->len = len; res->skip = start; diff --git a/src/stralloc.c b/src/stralloc.c index 184f4518fbd258390c57617265d19282069d1875..4b0b2ec28c08e49123950065d8743480a4069bc1 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -613,8 +613,7 @@ static void stralloc_rehash(void) SET_HSIZE( ++hashprimes_entry ); - base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size); - MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size); + base_table=xcalloc(sizeof(struct pike_string *), htable_size); need_more_hash_prefix_depth = 0; @@ -2225,8 +2224,8 @@ void init_shared_string_table(void) { for(hashprimes_entry=0;hashprimes[hashprimes_entry]<BEGIN_HASH_SIZE;hashprimes_entry++); SET_HSIZE(hashprimes_entry); - base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size); - MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size); + base_table=xcalloc(sizeof(struct pike_string *), htable_size); + #ifdef PIKE_RUN_UNLOCKED { int h;