Skip to content

Commit

Permalink
Merge pull request #10 from mcfrisk/coverity_review_fixes_v2
Browse files Browse the repository at this point in the history
Coverity review fixes v2
  • Loading branch information
ddennedy committed Aug 7, 2012
2 parents 9891279 + 7a4a454 commit 9b64e66
Show file tree
Hide file tree
Showing 30 changed files with 200 additions and 57 deletions.
9 changes: 6 additions & 3 deletions src/modules/avformat/consumer_avformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,12 @@ static AVStream *add_video_stream( mlt_consumer consumer, AVFormatContext *oc, A
mlt_log_fatal( MLT_CONSUMER_SERVICE( consumer ), "Could not allocate log buffer\n" );
else
{
size = fread( logbuffer, 1, size, f );
logbuffer[size] = '\0';
c->stats_in = logbuffer;
if ( size >= 0 )
{
size = fread( logbuffer, 1, size, f );
logbuffer[size] = '\0';
c->stats_in = logbuffer;
}
}
fclose( f );
}
Expand Down
10 changes: 7 additions & 3 deletions src/modules/core/filter_data_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ static mlt_filter obtain_filter( mlt_filter filter, char *type )
else if ( strchr( profile, '%' ) )
sprintf( temp, "%s/feeds/%s/%s", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ), strchr( profile, '%' ) + 1 );
else
strcpy( temp, profile );
{
strncpy( temp, profile, sizeof( temp ) );
temp[ sizeof( temp ) - 1 ] = '\0';
}

// Load the specified profile or use the default
profile_properties = mlt_properties_load( temp );
Expand Down Expand Up @@ -207,7 +210,7 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame
// special case: replace #timecode# with current frame timecode
int pos = mlt_properties_get_int( feed, "position" );
char *tc = frame_to_timecode( pos, mlt_profile_fps( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ) ) );
strcat( result, tc );
strncat( result, tc, sizeof( result ) - strlen( result ) - 1 );
free( tc );
}
else if ( !strcmp( keywords, "frame" ) )
Expand All @@ -216,13 +219,14 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame
int pos = mlt_properties_get_int( feed, "position" );
char s[12];
snprintf( s, sizeof(s) - 1, "%d", pos );
s[sizeof( s ) - 1] = '\0';
strcat( result, s );
}
else
{
// replace keyword with metadata value
char *metavalue = metadata_value( MLT_FRAME_PROPERTIES( frame ), keywords );
strcat( result, metavalue ? metavalue : "-" );
strncat( result, metavalue ? metavalue : "-", sizeof( result ) - strlen( result ) -1 );
}
keywords = strtok( NULL, "#" );
ct++;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/core/producer_melt.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ mlt_producer producer_melt_init( mlt_profile profile, mlt_service_type type, con
track_service( field, playlist, ( mlt_destructor )mlt_playlist_close );

// We must have a playlist to connect
if ( !mlt_properties_get_int( MLT_PLAYLIST_PROPERTIES( playlist ), "_melt_first" ) ||
if ( playlist && !mlt_properties_get_int( MLT_PLAYLIST_PROPERTIES( playlist ), "_melt_first" ) ||
mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( playlist ) ) > 0 )
mlt_multitrack_connect( multitrack, MLT_PLAYLIST_PRODUCER( playlist ), track );

Expand Down
3 changes: 2 additions & 1 deletion src/modules/core/transition_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static int create_instance( mlt_transition transition, char *name, char *value,

// Create the filter
mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( transition ) );
filter = mlt_factory_filter( profile, type, arg );
if ( type )
filter = mlt_factory_filter( profile, type, arg );

// If we have a filter, then initialise and store it
if ( filter != NULL )
Expand Down
3 changes: 2 additions & 1 deletion src/modules/dv/producer_libdv.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
}

// Update timecode on the frame we're creating
mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
if ( *frame != NULL )
mlt_frame_set_position( *frame, mlt_producer_position( producer ) );

// Calculate the next timecode
mlt_producer_prepare_next( producer );
Expand Down
15 changes: 8 additions & 7 deletions src/modules/frei0r/factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ static void * load_lib( mlt_profile profile, mlt_service_type type , void* handl
}
}
check_thread_safe( properties, name );
mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof (void*) , NULL , NULL );
mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof ( handle ) , NULL , NULL );
mlt_properties_set_data(properties, "_dlclose", dlclose , sizeof (void*) , NULL , NULL );
mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof( f0r_construct ),NULL,NULL);
mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof( f0r_update ),NULL,NULL);
if (f0r_update2)
mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof( f0r_update2 ),NULL,NULL);
mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof( f0r_destruct ),NULL,NULL);
mlt_properties_set_data(properties, "f0r_get_plugin_info", f0r_get_plugin_info , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_get_param_info", f0r_get_param_info , sizeof(void*),NULL,NULL);
mlt_properties_set_data(properties, "f0r_set_param_value", f0r_set_param_value , sizeof(void*),NULL,NULL);
Expand Down Expand Up @@ -387,9 +387,10 @@ MLT_REPOSITORY
char* firstname = strtok_r( shortname, ".", &save_firstptr );
#endif
char pluginname[1024]="frei0r.";
strcat(pluginname,firstname);
if ( firstname )
strncat( pluginname, firstname, sizeof( pluginname ) - strlen( pluginname ) -1 );

if ( mlt_properties_get( blacklist, firstname ) )
if ( firstname && mlt_properties_get( blacklist, firstname ) )
continue;

void* handle=dlopen(strcat(name, LIBSUF),RTLD_LAZY);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/frei0r/frei0r_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int process_frei0r_item( mlt_service service, double position, double time, mlt_
}
if ( neu == 0 ){
inst= f0r_construct(*width,*height);
mlt_properties_set_data( prop , ctorname , inst, sizeof(void*) , f0r_destruct , NULL );;
mlt_properties_set_data( prop , ctorname , inst, sizeof( inst ) , f0r_destruct , NULL );;
}else{
inst=mlt_properties_get_data( prop , ctorname , NULL );
}
Expand Down
12 changes: 8 additions & 4 deletions src/modules/gtk2/producer_pango.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ mlt_producer producer_pango_init( const char *filename )
if ( markup )
{
markup = realloc( markup, size );
strcat( markup, line );
if ( markup )
strcat( markup, line );
}
else
{
Expand All @@ -225,11 +226,14 @@ mlt_producer producer_pango_init( const char *filename )
}
fclose( f );

if ( markup[ strlen( markup ) - 1 ] == '\n' )
if ( markup && markup[ strlen( markup ) - 1 ] == '\n' )
markup[ strlen( markup ) - 1 ] = '\0';

mlt_properties_set( properties, "resource", filename );
mlt_properties_set( properties, "markup", ( markup == NULL ? "" : markup ) );
if ( markup )
mlt_properties_set( properties, "markup", markup );
else
mlt_properties_set( properties, "markup", "" );
free( markup );
}
else
Expand Down Expand Up @@ -306,7 +310,7 @@ static int iconv_utf8( mlt_properties properties, const char *prop_name, const c
int result = -1;

iconv_t cd = iconv_open( "UTF-8", encoding );
if ( cd != ( iconv_t )-1 )
if ( text && ( cd != ( iconv_t )-1 ) )
{
char *inbuf_p = text;
size_t inbuf_n = strlen( text );
Expand Down
6 changes: 5 additions & 1 deletion src/modules/jackrack/consumer_jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ static void initialise_jack_ports( consumer_jack self )
if ( !ports )
ports = jack_get_ports( self->jack, NULL, NULL, JackPortIsPhysical | JackPortIsInput );
if ( ports )
strcpy( con_name, ports[i] );
strncpy( con_name, ports[i], sizeof( con_name ));
else
snprintf( con_name, sizeof( con_name ), "system:playback_%d", i + 1);
con_name[ sizeof( con_name ) - 1 ] = '\0';
}
mlt_log_verbose( NULL, "JACK connect %s to %s\n", mlt_name, con_name );
jack_connect( self->jack, mlt_name, con_name );
Expand Down Expand Up @@ -484,7 +485,10 @@ static void *consumer_thread( void *arg )
int64_t playtime = 0;
struct timespec tm = { 0, 100000 };
// int last_position = -1;

pthread_mutex_lock( &self->refresh_mutex );
self->refresh_count = 0;
pthread_mutex_unlock( &self->refresh_mutex );

// Loop until told not to
while( self->running )
Expand Down
5 changes: 4 additions & 1 deletion src/modules/jackrack/jack_rack.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ jack_rack_add_plugin (jack_rack_t * jack_rack, plugin_t * plugin)
}
saved_plugin = NULL;
}


if ( !saved_plugin )
return;

/* initialize plugin parameters */
plugin->enabled = settings_get_enabled (saved_plugin->settings);
plugin->wet_dry_enabled = settings_get_wet_dry_enabled (saved_plugin->settings);
Expand Down
16 changes: 12 additions & 4 deletions src/modules/kdenlive/producer_framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ static int framebuffer_get_image( mlt_frame frame, uint8_t **image, mlt_image_fo

static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
{
// Construct a new frame
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
if( frame != NULL )
if ( frame )
{
// Construct a new frame
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );

// Stack the producer and producer's get image
mlt_frame_push_service( *frame, (void*) index );
mlt_frame_push_service( *frame, producer );
Expand Down Expand Up @@ -251,7 +252,14 @@ mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type ty
if ( !arg ) return NULL;
mlt_producer producer = NULL;
producer = calloc( 1, sizeof( struct mlt_producer_s ) );
mlt_producer_init( producer, NULL );
if ( !producer )
return NULL;

if ( mlt_producer_init( producer, NULL ) )
{
free( producer );
return NULL;
}

// Wrap loader
mlt_producer real_producer;
Expand Down
10 changes: 9 additions & 1 deletion src/modules/kino/avi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ AVIFile::AVIFile() : RIFFFile(),
}
idx1 = new AVISimpleIndex;
memset( idx1, 0, sizeof( AVISimpleIndex ) );
memset( dmlh, 0, sizeof( dmlh ) );
memset( &mainHdr, 0, sizeof( mainHdr ) );
memset( &streamHdr, 0, sizeof( streamHdr ) );
}


Expand Down Expand Up @@ -133,6 +136,9 @@ AVIFile::AVIFile( const AVIFile& avi ) : RIFFFile( avi )

isUpdateIdx1 = avi.isUpdateIdx1;

odml_list = 0;
dmlh_chunk = 0;
memset( &streamHdr, 0, sizeof( streamHdr ) );
}


Expand Down Expand Up @@ -995,7 +1001,9 @@ bool AVIFile::isOpenDML( void )
}

AVI1File::AVI1File() : AVIFile()
{}
{
memset( &dvinfo, 0, sizeof( dvinfo ) );
}


AVI1File::~AVI1File()
Expand Down
9 changes: 8 additions & 1 deletion src/modules/kino/filehandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ FileHandler::FileHandler() : done( false ), autoSplit( false ), maxFrameCount( 9
framesWritten( 0 ), filename( "" )
{
/* empty body */
timeStamp = 0;
everyNthFrame = 0;
framesToSkip = 0;
maxFileSize = 0;
}


Expand Down Expand Up @@ -338,6 +342,7 @@ bool FileHandler::WriteFrame( const Frame& frame )
RawHandler::RawHandler() : fd( -1 )
{
extension = ".dv";
numBlocks = 0;
}


Expand Down Expand Up @@ -406,7 +411,8 @@ bool RawHandler::Open( const char *s )
return false;
if ( read( fd, data, 4 ) < 0 )
return false;
lseek( fd, 0, SEEK_SET );
if ( lseek( fd, 0, SEEK_SET ) < 0 )
return false;
numBlocks = ( ( data[ 3 ] & 0x80 ) == 0 ) ? 250 : 300;
filename = s;
return true;
Expand Down Expand Up @@ -438,6 +444,7 @@ AVIHandler::AVIHandler( int format ) : avi( NULL ), aviFormat( format ), isOpenD
extension = ".avi";
for ( int c = 0; c < 4; c++ )
audioChannels[ c ] = NULL;
memset( &dvinfo, 0, sizeof( dvinfo ) );
}


Expand Down
10 changes: 7 additions & 3 deletions src/modules/linsys/consumer_SDIstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ static void *consumer_thread(void *arg) {

// Set additional device file defaults
struct stat st;
int fd = stat(this->device_file_video, &st);
int fd = -1;
if (this->device_file_video)
fd = stat(this->device_file_video, &st);
if (fd == -1) {
if (this->device_file_video)
free(this->device_file_video);
Expand All @@ -376,7 +378,8 @@ static void *consumer_thread(void *arg) {
} else {
close(fd);
}
} else if (strstr(this->device_file_video, "sdivideotx")) {
} else if (this->device_file_video &&
strstr(this->device_file_video, "sdivideotx")) {
if (this->device_file_audio)
free(this->device_file_audio);
this->device_file_audio = strdup("/dev/sdiaudiotx0");
Expand Down Expand Up @@ -419,7 +422,8 @@ static void *consumer_thread(void *arg) {
this->audio_format.sample_rate = 48000;
this->pix_fmt = mlt_image_yuv422;

if (!sdi_init(this->device_file_video, this->device_file_audio, this->blanking, mlt_service_profile((mlt_service) consumer), &this->audio_format)) {
if (this->device_file_video && this->device_file_audio &&
!sdi_init(this->device_file_video, this->device_file_audio, this->blanking, mlt_service_profile((mlt_service) consumer), &this->audio_format)) {
mlt_log_fatal( MLT_CONSUMER_SERVICE(consumer), "failed to initialize\n" );
mlt_events_fire( MLT_CONSUMER_PROPERTIES(consumer), "consumer-fatal-error", NULL );
}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/linsys/sdi_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ static int sdi_init(char *device_video, char *device_audio, uint8_t blanking, ml
}

if (info.blanking) {
printf("SDI frame size: %li\n", sdi_frame_size);
printf("SDI frame size: %"PRIu64"\n", sdi_frame_size);
} else {
printf("Frame size for active video: %li\n", sdi_frame_size);
printf("Frame size for active video: %"PRIu64"\n", sdi_frame_size);
}

/**
Expand Down Expand Up @@ -420,8 +420,8 @@ static int sdi_init(char *device_video, char *device_audio, uint8_t blanking, ml
// Buffer size
// audio buffer per frame (Bytes) = sample rate / frame rate * ( sample size / 1Byte ) x channels
value = itoa(
audio_format->sample_rate / (myProfile->frame_rate_num / myProfile->frame_rate_den) * sample_size / 8
* audio_format->channels);
(uint64_t) audio_format->sample_rate / ( (uint64_t) myProfile->frame_rate_num / (uint64_t) myProfile->frame_rate_den) * (uint64_t) sample_size / 8
* (uint64_t) audio_format->channels);
setSDIAudioProperties(SETTING_BUFFER_SIZE_AUDIO, value, device_audio);
free(value);

Expand Down
26 changes: 23 additions & 3 deletions src/modules/lumas/luma.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,31 @@ int main( int argc, char **argv )
else if ( !strcmp( argv[ arg ], "-type" ) )
this.type = atoi( argv[ ++ arg ] );
else if ( !strcmp( argv[ arg ], "-w" ) )
this.w = atoi( argv[ ++ arg ] );
{
int tmp = atoi( argv[ ++ arg ] );
// TODO: is there an upper bound?
if ( tmp )
this.w = tmp;
else
return 1;
}
else if ( !strcmp( argv[ arg ], "-h" ) )
this.h = atoi( argv[ ++ arg ] );
{
int tmp = atoi( argv[ ++ arg ] );
// TODO: is there an upper bound?
if ( tmp )
this.h = tmp;
else return 1;
}
else if ( !strcmp( argv[ arg ], "-bands" ) )
this.bands = atoi( argv[ ++ arg ] );
{
int tmp = atoi( argv[ ++ arg ] );
// TODO: is there an upper bound?
if ( tmp >= 0 )
this.bands = tmp;
else
return 1;
}
else if ( !strcmp( argv[ arg ], "-rband" ) )
this.rband = atoi( argv[ ++ arg ] );
else if ( !strcmp( argv[ arg ], "-hmirror" ) )
Expand Down
2 changes: 2 additions & 0 deletions src/modules/motion_est/producer_slowmotion.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ static int slowmotion_get_image( mlt_frame this, uint8_t **image, mlt_image_form

static int slowmotion_get_frame( mlt_producer this, mlt_frame_ptr frame, int index )
{
if ( !frame )
return 1;
// Construct a new frame
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) );

Expand Down
Loading

0 comments on commit 9b64e66

Please sign in to comment.