switch malloc+memset(0) to calloc()

This commit is contained in:
Josh Coalson 2002-10-18 05:49:19 +00:00
parent a987ab456d
commit ea7155f0ac
13 changed files with 48 additions and 91 deletions

View File

@ -140,10 +140,9 @@ static FLAC__bool bitbuffer_resize_(FLAC__BitBuffer *bb, unsigned new_capacity)
if(bb->capacity == new_capacity)
return true;
new_buffer = (FLAC__blurb*)malloc(sizeof(FLAC__blurb) * new_capacity);
new_buffer = (FLAC__blurb*)calloc(new_capacity, sizeof(FLAC__blurb));
if(new_buffer == 0)
return false;
memset(new_buffer, 0, sizeof(FLAC__blurb) * new_capacity);
memcpy(new_buffer, bb->buffer, sizeof(FLAC__blurb)*min(bb->blurbs+(bb->bits?1:0), new_capacity));
if(new_capacity < bb->blurbs+(bb->bits?1:0)) {
bb->blurbs = new_capacity;
@ -251,15 +250,15 @@ static FLAC__bool bitbuffer_read_from_client_(FLAC__BitBuffer *bb, FLAC__bool (*
FLAC__BitBuffer *FLAC__bitbuffer_new()
{
FLAC__BitBuffer *bb = (FLAC__BitBuffer*)malloc(sizeof(FLAC__BitBuffer));
FLAC__BitBuffer *bb = (FLAC__BitBuffer*)calloc(1, sizeof(FLAC__BitBuffer));
if(0 != bb) {
/* calloc() implies:
memset(bb, 0, sizeof(FLAC__BitBuffer));
bb->buffer = 0;
bb->capacity = 0;
bb->blurbs = bb->bits = bb->total_bits = 0;
bb->consumed_blurbs = bb->consumed_bits = bb->total_consumed_bits = 0;
}
*/
return bb;
}
@ -357,10 +356,9 @@ FLAC__bool FLAC__bitbuffer_clear(FLAC__BitBuffer *bb)
{
if(bb->buffer == 0) {
bb->capacity = FLAC__BITBUFFER_DEFAULT_CAPACITY;
bb->buffer = (FLAC__blurb*)malloc(sizeof(FLAC__blurb) * bb->capacity);
bb->buffer = (FLAC__blurb*)calloc(bb->capacity, sizeof(FLAC__blurb));
if(bb->buffer == 0)
return false;
memset(bb->buffer, 0, bb->capacity);
}
else {
memset(bb->buffer, 0, bb->blurbs + (bb->bits?1:0));

View File

@ -96,26 +96,23 @@ FLAC_API FLAC__FileDecoder *FLAC__file_decoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
decoder = (FLAC__FileDecoder*)malloc(sizeof(FLAC__FileDecoder));
decoder = (FLAC__FileDecoder*)calloc(1, sizeof(FLAC__FileDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(FLAC__FileDecoder));
decoder->protected_ = (FLAC__FileDecoderProtected*)malloc(sizeof(FLAC__FileDecoderProtected));
decoder->protected_ = (FLAC__FileDecoderProtected*)calloc(1, sizeof(FLAC__FileDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(FLAC__FileDecoderProtected));
decoder->private_ = (FLAC__FileDecoderPrivate*)malloc(sizeof(FLAC__FileDecoderPrivate));
decoder->private_ = (FLAC__FileDecoderPrivate*)calloc(1, sizeof(FLAC__FileDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(FLAC__FileDecoderPrivate));
decoder->private_->seekable_stream_decoder = FLAC__seekable_stream_decoder_new();
if(0 == decoder->private_->seekable_stream_decoder) {

View File

@ -86,26 +86,23 @@ FLAC_API FLAC__FileEncoder *FLAC__file_encoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
encoder = (FLAC__FileEncoder*)malloc(sizeof(FLAC__FileEncoder));
encoder = (FLAC__FileEncoder*)calloc(1, sizeof(FLAC__FileEncoder));
if(encoder == 0) {
return 0;
}
memset(encoder, 0, sizeof(FLAC__FileEncoder));
encoder->protected_ = (FLAC__FileEncoderProtected*)malloc(sizeof(FLAC__FileEncoderProtected));
encoder->protected_ = (FLAC__FileEncoderProtected*)calloc(1, sizeof(FLAC__FileEncoderProtected));
if(encoder->protected_ == 0) {
free(encoder);
return 0;
}
memset(encoder->protected_, 0, sizeof(FLAC__FileEncoderProtected));
encoder->private_ = (FLAC__FileEncoderPrivate*)malloc(sizeof(FLAC__FileEncoderPrivate));
encoder->private_ = (FLAC__FileEncoderPrivate*)calloc(1, sizeof(FLAC__FileEncoderPrivate));
if(encoder->private_ == 0) {
free(encoder->protected_);
free(encoder);
return 0;
}
memset(encoder->private_, 0, sizeof(FLAC__FileEncoderPrivate));
encoder->private_->seekable_stream_encoder = FLAC__seekable_stream_encoder_new();
if(0 == encoder->private_->seekable_stream_encoder) {

View File

@ -242,7 +242,7 @@ FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[] = {
FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new()
{
FLAC__Metadata_SimpleIterator *iterator = malloc(sizeof(FLAC__Metadata_SimpleIterator));
FLAC__Metadata_SimpleIterator *iterator = calloc(1, sizeof(FLAC__Metadata_SimpleIterator));
if(0 != iterator) {
iterator->file = 0;
@ -748,10 +748,7 @@ FLAC_API const char * const FLAC__Metadata_ChainStatusString[] = {
static FLAC__Metadata_Node *node_new_()
{
FLAC__Metadata_Node *node = (FLAC__Metadata_Node*)malloc(sizeof(FLAC__Metadata_Node));
if(0 != node)
memset(node, 0, sizeof(FLAC__Metadata_Node));
return node;
return (FLAC__Metadata_Node*)calloc(1, sizeof(FLAC__Metadata_Node));
}
static void node_delete_(FLAC__Metadata_Node *node)
@ -888,7 +885,7 @@ static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLA
FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new()
{
FLAC__Metadata_Chain *chain = malloc(sizeof(FLAC__Metadata_Chain));
FLAC__Metadata_Chain *chain = calloc(1, sizeof(FLAC__Metadata_Chain));
if(0 != chain) {
chain->filename = 0;
@ -1102,12 +1099,12 @@ FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain)
FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new()
{
FLAC__Metadata_Iterator *iterator = malloc(sizeof(FLAC__Metadata_Iterator));
FLAC__Metadata_Iterator *iterator = calloc(1, sizeof(FLAC__Metadata_Iterator));
if(0 != iterator) {
/* calloc() implies:
iterator->current = 0;
iterator->chain = 0;
}
*/
return iterator;
}

View File

@ -111,16 +111,9 @@ static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object)
static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(unsigned num_comments)
{
FLAC__StreamMetadata_VorbisComment_Entry *object_array;
FLAC__ASSERT(num_comments > 0);
object_array = malloc(num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
if(0 != object_array)
memset(object_array, 0, num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
return object_array;
return calloc(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
}
static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
@ -204,9 +197,8 @@ static FLAC__bool vorbiscomment_set_entry_(FLAC__StreamMetadata *object, FLAC__S
FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type)
{
FLAC__StreamMetadata *object = malloc(sizeof(FLAC__StreamMetadata));
FLAC__StreamMetadata *object = calloc(1, sizeof(FLAC__StreamMetadata));
if(0 != object) {
memset(object, 0, sizeof(FLAC__StreamMetadata));
object->is_last = false;
object->type = type;
switch(type) {

View File

@ -18,7 +18,7 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <stdlib.h> /* for calloc() */
#include <string.h> /* for memcpy()/memcmp() */
#include "FLAC/assert.h"
#include "protected/seekable_stream_decoder.h"
@ -121,26 +121,23 @@ FLAC_API FLAC__SeekableStreamDecoder *FLAC__seekable_stream_decoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
decoder = (FLAC__SeekableStreamDecoder*)malloc(sizeof(FLAC__SeekableStreamDecoder));
decoder = (FLAC__SeekableStreamDecoder*)calloc(1, sizeof(FLAC__SeekableStreamDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(FLAC__SeekableStreamDecoder));
decoder->protected_ = (FLAC__SeekableStreamDecoderProtected*)malloc(sizeof(FLAC__SeekableStreamDecoderProtected));
decoder->protected_ = (FLAC__SeekableStreamDecoderProtected*)calloc(1, sizeof(FLAC__SeekableStreamDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(FLAC__SeekableStreamDecoderProtected));
decoder->private_ = (FLAC__SeekableStreamDecoderPrivate*)malloc(sizeof(FLAC__SeekableStreamDecoderPrivate));
decoder->private_ = (FLAC__SeekableStreamDecoderPrivate*)calloc(1, sizeof(FLAC__SeekableStreamDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(FLAC__SeekableStreamDecoderPrivate));
decoder->private_->stream_decoder = FLAC__stream_decoder_new();
if(0 == decoder->private_->stream_decoder) {

View File

@ -18,7 +18,7 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <stdlib.h> /* for calloc() */
#include <string.h> /* for memcpy() */
#include "FLAC/assert.h"
#include "protected/seekable_stream_encoder.h"
@ -99,26 +99,23 @@ FLAC_API FLAC__SeekableStreamEncoder *FLAC__seekable_stream_encoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
encoder = (FLAC__SeekableStreamEncoder*)malloc(sizeof(FLAC__SeekableStreamEncoder));
encoder = (FLAC__SeekableStreamEncoder*)calloc(1, sizeof(FLAC__SeekableStreamEncoder));
if(encoder == 0) {
return 0;
}
memset(encoder, 0, sizeof(FLAC__SeekableStreamEncoder));
encoder->protected_ = (FLAC__SeekableStreamEncoderProtected*)malloc(sizeof(FLAC__SeekableStreamEncoderProtected));
encoder->protected_ = (FLAC__SeekableStreamEncoderProtected*)calloc(1, sizeof(FLAC__SeekableStreamEncoderProtected));
if(encoder->protected_ == 0) {
free(encoder);
return 0;
}
memset(encoder->protected_, 0, sizeof(FLAC__SeekableStreamEncoderProtected));
encoder->private_ = (FLAC__SeekableStreamEncoderPrivate*)malloc(sizeof(FLAC__SeekableStreamEncoderPrivate));
encoder->private_ = (FLAC__SeekableStreamEncoderPrivate*)calloc(1, sizeof(FLAC__SeekableStreamEncoderPrivate));
if(encoder->private_ == 0) {
free(encoder->protected_);
free(encoder);
return 0;
}
memset(encoder->private_, 0, sizeof(FLAC__SeekableStreamEncoderPrivate));
encoder->private_->stream_encoder = FLAC__stream_encoder_new();
if(0 == encoder->private_->stream_encoder) {

View File

@ -150,26 +150,23 @@ FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
decoder = (FLAC__StreamDecoder*)malloc(sizeof(FLAC__StreamDecoder));
decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(FLAC__StreamDecoder));
decoder->protected_ = (FLAC__StreamDecoderProtected*)malloc(sizeof(FLAC__StreamDecoderProtected));
decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(FLAC__StreamDecoderProtected));
decoder->private_ = (FLAC__StreamDecoderPrivate*)malloc(sizeof(FLAC__StreamDecoderPrivate));
decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(FLAC__StreamDecoderPrivate));
decoder->private_->input = FLAC__bitbuffer_new();
if(decoder->private_->input == 0) {

View File

@ -430,26 +430,23 @@ FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
encoder = (FLAC__StreamEncoder*)malloc(sizeof(FLAC__StreamEncoder));
encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
if(encoder == 0) {
return 0;
}
memset(encoder, 0, sizeof(FLAC__StreamEncoder));
encoder->protected_ = (FLAC__StreamEncoderProtected*)malloc(sizeof(FLAC__StreamEncoderProtected));
encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
if(encoder->protected_ == 0) {
free(encoder);
return 0;
}
memset(encoder->protected_, 0, sizeof(FLAC__StreamEncoderProtected));
encoder->private_ = (FLAC__StreamEncoderPrivate*)malloc(sizeof(FLAC__StreamEncoderPrivate));
encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
if(encoder->private_ == 0) {
free(encoder->protected_);
free(encoder);
return 0;
}
memset(encoder->private_, 0, sizeof(FLAC__StreamEncoderPrivate));
encoder->private_->frame = FLAC__bitbuffer_new();
if(encoder->private_->frame == 0) {

View File

@ -96,26 +96,23 @@ OggFLAC_API FLAC__FileDecoder *FLAC__file_decoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
decoder = (FLAC__FileDecoder*)malloc(sizeof(FLAC__FileDecoder));
decoder = (FLAC__FileDecoder*)calloc(1, sizeof(FLAC__FileDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(FLAC__FileDecoder));
decoder->protected_ = (FLAC__FileDecoderProtected*)malloc(sizeof(FLAC__FileDecoderProtected));
decoder->protected_ = (FLAC__FileDecoderProtected*)calloc(1, sizeof(FLAC__FileDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(FLAC__FileDecoderProtected));
decoder->private_ = (FLAC__FileDecoderPrivate*)malloc(sizeof(FLAC__FileDecoderPrivate));
decoder->private_ = (FLAC__FileDecoderPrivate*)calloc(1, sizeof(FLAC__FileDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(FLAC__FileDecoderPrivate));
decoder->private_->seekable_stream_decoder = FLAC__seekable_stream_decoder_new();
if(0 == decoder->private_->seekable_stream_decoder) {

View File

@ -18,7 +18,7 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <stdlib.h> /* for calloc() */
#include <string.h> /* for memcpy()/memcmp() */
#include "FLAC/assert.h"
#include "protected/seekable_stream_decoder.h"
@ -121,26 +121,23 @@ OggFLAC_API FLAC__SeekableStreamDecoder *FLAC__seekable_stream_decoder_new()
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
decoder = (FLAC__SeekableStreamDecoder*)malloc(sizeof(FLAC__SeekableStreamDecoder));
decoder = (FLAC__SeekableStreamDecoder*)calloc(1, sizeof(FLAC__SeekableStreamDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(FLAC__SeekableStreamDecoder));
decoder->protected_ = (FLAC__SeekableStreamDecoderProtected*)malloc(sizeof(FLAC__SeekableStreamDecoderProtected));
decoder->protected_ = (FLAC__SeekableStreamDecoderProtected*)calloc(1, sizeof(FLAC__SeekableStreamDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(FLAC__SeekableStreamDecoderProtected));
decoder->private_ = (FLAC__SeekableStreamDecoderPrivate*)malloc(sizeof(FLAC__SeekableStreamDecoderPrivate));
decoder->private_ = (FLAC__SeekableStreamDecoderPrivate*)calloc(1, sizeof(FLAC__SeekableStreamDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(FLAC__SeekableStreamDecoderPrivate));
decoder->private_->stream_decoder = FLAC__stream_decoder_new();
if(0 == decoder->private_->stream_decoder) {

View File

@ -17,7 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdlib.h> /* for calloc() */
#include <string.h> /* for memset() */
#include "ogg/ogg.h"
#include "FLAC/assert.h"
@ -88,26 +88,23 @@ OggFLAC_API OggFLAC__StreamDecoder *OggFLAC__stream_decoder_new()
{
OggFLAC__StreamDecoder *decoder;
decoder = (OggFLAC__StreamDecoder*)malloc(sizeof(OggFLAC__StreamDecoder));
decoder = (OggFLAC__StreamDecoder*)calloc(1, sizeof(OggFLAC__StreamDecoder));
if(decoder == 0) {
return 0;
}
memset(decoder, 0, sizeof(OggFLAC__StreamDecoder));
decoder->protected_ = (OggFLAC__StreamDecoderProtected*)malloc(sizeof(OggFLAC__StreamDecoderProtected));
decoder->protected_ = (OggFLAC__StreamDecoderProtected*)calloc(1, sizeof(OggFLAC__StreamDecoderProtected));
if(decoder->protected_ == 0) {
free(decoder);
return 0;
}
memset(decoder->protected_, 0, sizeof(OggFLAC__StreamDecoderProtected));
decoder->private_ = (OggFLAC__StreamDecoderPrivate*)malloc(sizeof(OggFLAC__StreamDecoderPrivate));
decoder->private_ = (OggFLAC__StreamDecoderPrivate*)calloc(1, sizeof(OggFLAC__StreamDecoderPrivate));
if(decoder->private_ == 0) {
free(decoder->protected_);
free(decoder);
return 0;
}
memset(decoder->private_, 0, sizeof(OggFLAC__StreamDecoderPrivate));
decoder->private_->FLAC_stream_decoder = FLAC__stream_decoder_new();
if(0 == decoder->private_->FLAC_stream_decoder) {

View File

@ -18,7 +18,7 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <stdlib.h> /* for calloc() */
#include <string.h> /* for memcpy() */
#include "ogg/ogg.h"
#include "FLAC/assert.h"
@ -87,26 +87,23 @@ OggFLAC_API OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new()
{
OggFLAC__StreamEncoder *encoder;
encoder = (OggFLAC__StreamEncoder*)malloc(sizeof(OggFLAC__StreamEncoder));
encoder = (OggFLAC__StreamEncoder*)calloc(1, sizeof(OggFLAC__StreamEncoder));
if(encoder == 0) {
return 0;
}
memset(encoder, 0, sizeof(OggFLAC__StreamEncoder));
encoder->protected_ = (OggFLAC__StreamEncoderProtected*)malloc(sizeof(OggFLAC__StreamEncoderProtected));
encoder->protected_ = (OggFLAC__StreamEncoderProtected*)calloc(1, sizeof(OggFLAC__StreamEncoderProtected));
if(encoder->protected_ == 0) {
free(encoder);
return 0;
}
memset(encoder->protected_, 0, sizeof(OggFLAC__StreamEncoderProtected));
encoder->private_ = (OggFLAC__StreamEncoderPrivate*)malloc(sizeof(OggFLAC__StreamEncoderPrivate));
encoder->private_ = (OggFLAC__StreamEncoderPrivate*)calloc(1, sizeof(OggFLAC__StreamEncoderPrivate));
if(encoder->private_ == 0) {
free(encoder->protected_);
free(encoder);
return 0;
}
memset(encoder->private_, 0, sizeof(OggFLAC__StreamEncoderPrivate));
encoder->private_->FLAC_stream_encoder = FLAC__stream_encoder_new();
if(0 == encoder->private_->FLAC_stream_encoder) {