consumer_avformat: handle negative return value

Fixes Coverity CID 709361: Argument cannot be negative (NEGATIVE_RETURNS)
Function "ftell(f)" returns a negative number.
Assigning: signed variable "size" = "ftell".
 937                                        size = ftell( f );
 938                                        fseek( f, 0, SEEK_SET );
 939                                        logbuffer = av_malloc( size + 1 );
At conditional (1): "!logbuffer" taking the false branch.
 940                                        if ( !logbuffer )
 941                                                mlt_log_fatal( MLT_CONSUMER_SERVICE( consumer ), "Could not allocate log buffer\n" );
 942                                        else
 943                                        {
"size" is passed to a parameter that cannot be negative.
 944                                                size = fread( logbuffer, 1, size, f );
filter_data_show.c: check dest buffer sizes

Fixes Coverity CID 709413: Copy into fixed size buffer (STRING_OVERFLOW)
You might overrun the 512 byte fixed-size string "temp" by copying "profile" without checking the length.
 58                        strcpy( temp, profile );

and

CID 709414: Copy into fixed size buffer (STRING_OVERFLOW)
You might overrun the 512 byte fixed-size string "result" by copying "metavalue" without checking the length.
225                                                                        strcat( result, metavalue ? metavalue : "-" );
producer_melt_init(): check for null pointer

Fixes Coverity CID 709349: Dereference after null check (FORWARD_NULL)
Comparing "playlist" to null implies that "playlist" might be null.
401                        if ( playlist != NULL )
...
Passing null variable "&playlist->parent.parent.parent" to function "mlt_properties_get_int", which dereferences it. [show details]
466        if ( !mlt_properties_get_int( MLT_PLAYLIST_PROPERTIES( playlist ), "_melt_first" ) ||
467                  mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( playlist ) ) > 0 )
468                mlt_multitrack_connect( multitrack, MLT_PLAYLIST_PRODUCER( playlist ), track );
transition_region.c: check for null pointer

Fixes Coverity CID 709350: Dereference after null check (FORWARD_NULL)
Comparing "type" to null implies that "type" might be null.
 39        char *arg = type == NULL ? NULL : strchr( type, ':' );
...
Passing null variable "type" to function "mlt_factory_filter", which dereferences it. [show details]
 50        filter = mlt_factory_filter( profile, type, arg );
producer_libdv.c: check for null pointer

Fixes Coverity CID 710856: Dereference after null check (FORWARD_NULL)
Comparing "*frame" to null implies that "*frame" might be null.
491                if ( *frame != NULL )
492                        data = mlt_properties_get_data( MLT_FRAME_PROPERTIES( *frame ), "dv_data", NULL );
493        }
494
At conditional (2): "data != NULL" taking the false branch.
495        if ( data != NULL )
...
Passing null variable "*frame" to function "mlt_frame_set_position", which dereferences it. [show details]
540        mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
frei0r/factory.c: fix sizeof() arguments

Fixes Coverity CID 709406: Wrong sizeof argument (SIZEOF_MISMATCH)
Passing argument "handle" of type "void *" and argument "8 /* sizeof (void *) */" to function "mlt_properties_set_data" is suspicious.
281                mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof (void*) , NULL , NULL );
282                mlt_properties_set_data(properties, "_dlclose", dlclose , sizeof (void*) , NULL , NULL );
CID 709406: Wrong sizeof argument (SIZEOF_MISMATCH) [select defect]
283                mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof(void*),NULL,NULL);
CID 709406: Wrong sizeof argument (SIZEOF_MISMATCH) [select defect]
284                mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof(void*),NULL,NULL);
285                if (f0r_update2)
286                        mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof(void*),NULL,NULL);
CID 709406: Wrong sizeof argument (SIZEOF_MISMATCH) [select defect]
287                mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof(void*),NULL,NULL);
frei0r/factory.c: fix possible buffer overflow and null dereference

Fixes Coverity CID 709415: Copy into fixed size buffer (STRING_OVERFLOW)
You might overrun the 1024 byte fixed-size string "pluginname" by copying "firstname" without checking the length.
390                        strcat(pluginname,firstname);

and

CID 709397: Dereference before null check (REVERSE_INULL)
Dereferencing pointer "firstname". (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
390                        strcat(pluginname,firstname);
frei0r/frei0r_helper.c: use correct argument to sizeof()

Fixes Coverity CID 709407: Wrong sizeof argument (SIZEOF_MISMATCH)
Passing argument "inst" of type "void *" and argument "8 /* sizeof (void *) */" to function "mlt_properties_set_data" is suspicious.
 79                mlt_properties_set_data(  prop  ,  ctorname , inst, sizeof(void*) , f0r_destruct , NULL );;
producer_pango_init(): check for null pointer

Fixes Coverity CID 710868: Dereference before null check (REVERSE_INULL)
Dereferencing pointer "markup". (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
219                                                strcat( markup, line );
...
Dereferencing pointer "markup". (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
228                                if ( markup[ strlen( markup ) - 1 ] == '\n' )
229                                        markup[ strlen( markup ) - 1 ] = '\0';
...
Dereferencing "markup" before a null check.
232                                mlt_properties_set( properties, "markup", ( markup == NULL ? "" : markup ) );
producer_pango.c: check for null pointer

Fixes Coverity CID 710867: Dereference before null check (REVERSE_INULL)
Dereferencing pointer "text". (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
312                size_t inbuf_n = strlen( text );
...
Dereferencing "text" before a null check.
319                if ( text != NULL && strcmp( text, "" ) && iconv( cd, &inbuf_p, &inbuf_n, &outbuf_p, &outbuf_n ) != -1 )
consumer_jack.c: fix possible buffer overflow

CID 710871: Copy into fixed size buffer (STRING_OVERFLOW)
You might overrun the 30 byte fixed-size string "con_name" by copying "ports[i]" without checking the length.
290                                strcpy( con_name, ports[i] );
consumer_jack.c: initialize refresh_count with mutex held

Fixes Coverity CID 709359.

Locking "self->refresh_mutex".
148                pthread_mutex_lock( &self->refresh_mutex );
consumer_jack_s.refresh_count is being accessed with lock "self->refresh_mutex" held.
149                self->refresh_count = self->refresh_count <= 0 ? 1 : self->refresh_count + 1;
150                pthread_cond_broadcast( &self->refresh_cond );
151                pthread_mutex_unlock( &self->refresh_mutex );
...
486//      int last_position = -1;
CID 709359: Data race condition (MISSING_LOCK)
Accessing variable "self->refresh_count" (consumer_jack_s.refresh_count) requires the consumer_jack_s.refresh_mutex lock.
487        self->refresh_count = 0;
...
Locking "self->refresh_mutex".
544                                pthread_mutex_lock( &self->refresh_mutex );
545                                if ( refresh == 0 && self->refresh_count <= 0 )
546                                {
547                                        consumer_play_video( self, frame );
548                                        pthread_cond_wait( &self->refresh_cond, &self->refresh_mutex );
549                                }
550                                mlt_frame_close( frame );
consumer_jack_s.refresh_count is being accessed with lock "self->refresh_mutex" held.
jack_rack_add_plugin(): handle null pointer

Fixes Coverity CID 710857: Explicit null dereferenced (FORWARD_NULL)
Assigning: "saved_plugin" = 0.
134      saved_plugin = NULL;
135    }
136
137  /* initialize plugin parameters */
Dereferencing null variable "saved_plugin".
138  plugin->enabled = settings_get_enabled (saved_plugin->settings);
kdenlive/producer_framebuffer.c: check for null pointer

Fixes Coverity CID 709398: Dereference before null check (REVERSE_INULL)
Directly dereferencing pointer "frame".
203        *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
Dereferencing "frame" before a null check.
204        if( frame != NULL )
kdenlive/producer_framebuffer.c: check return values

Check calloc() return and fix Coverity CID 709328: Unchecked return value (CHECKED_RETURN)
Calling function "mlt_producer_init" without checking return value (as is done elsewhere 19 out of 20 times).
No check of the return value of "mlt_producer_init(producer, NULL)".
254        mlt_producer_init( producer, NULL );
kino/avi.cc: initialize variables

Fixes Coverity CID 709438: Uninitialized scalar field (UNINIT_CTOR)
Non-static class member ""dmlh"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwFlags" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwHeight" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwInitialFrames" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwMaxBytesPerSec" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwMicroSecPerFrame" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwPaddingGranularity" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwReserved" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwStreams" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwSuggestedBufferSize" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwTotalFrames" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "mainHdr.dwWidth" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwFlags" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwInitialFrames" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwLength" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwQuality" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwRate" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwSampleSize" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwScale" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwStart" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwSuggestedBufferSize" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.fccHandler" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.fccType" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.rcFrame" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.wLanguage" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.wPriority" is not initialized in this constructor nor in any functions that it calls.
kino/avi.cc: initialize variables

Fixes Coverity CID 709437: Uninitialized scalar field (UNINIT_CTOR)
Non-static class member ""dmlh_chunk"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member ""odml_list"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwFlags" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwInitialFrames" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwLength" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwQuality" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwRate" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwSampleSize" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwScale" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwStart" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.dwSuggestedBufferSize" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.fccHandler" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.fccType" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.rcFrame" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.wLanguage" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "streamHdr.wPriority" is not initialized in this constructor nor in any functions that it calls.
kino/avi.cc: initialize variable

Fixes Coverity CID 709439: Uninitialized scalar field (UNINIT_CTOR)
Non-static class member field "dvinfo.dwDVAAuxCtl1" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVAAuxCtl" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVAAuxSrc1" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVAAuxSrc" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVReserved" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVVAuxCtl" is not initialized in this constructor nor in any functions that it calls.
Non-static class member field "dvinfo.dwDVVAuxSrc" is not initialized in this constructor nor in any functions that it calls.
kino/filehandler.cc: initialize variables

Fixes Coverity CID 709443: Uninitialized scalar field (UNINIT_CTOR)
Non-static class member ""everyNthFrame"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member ""framesToSkip"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member ""maxFileSize"" is not initialized in this constructor nor in any functions that it calls.
Non-static class member ""timeStamp"" is not initialized in this constructor nor in any functions that it calls.
kino/filehandler.cc: initialize variable

Fixes Coverity CID 709442: Uninitialized scalar field (UNINIT_CTOR)
Non-static class member ""numBlocks"" is not initialized in this constructor nor in any functions that it calls.