]> granicus.if.org Git - handbrake/commitdiff
libhb: fix a number of issues reported by clang.
authorDamiano Galassi <damiog@gmail.com>
Fri, 12 Jan 2018 19:54:08 +0000 (20:54 +0100)
committerDamiano Galassi <galad87@users.noreply.github.com>
Fri, 12 Jan 2018 19:55:14 +0000 (20:55 +0100)
12 files changed:
libhb/batch.c
libhb/common.c
libhb/decavcodec.c
libhb/deccc608sub.c
libhb/decvobsub.c
libhb/encx264.c
libhb/hb_json.c
libhb/muxcommon.c
libhb/param.c
libhb/platform/macosx/encca_aac.c
libhb/preset.c
libhb/stream.c

index 1ae70d9ec6548d424d400aab05a377fce84403bf..050d1e0c84dc67448743de21d65f378d2304c5b7 100644 (file)
@@ -53,6 +53,12 @@ hb_batch_t * hb_batch_init( hb_handle_t *h, char * path )
     {
         count++;
     }
+
+    if (count == 0)
+    {
+        return NULL;
+    }
+
     files = malloc(count * sizeof(char*));
 
     // Find all regular files
index 301f121dda71c01797d2c1b2d492f9c0a73ed795..80ccf9f176d8d15fc13e4484532144de8c2a3e9b 100644 (file)
@@ -874,6 +874,13 @@ int hb_audio_samplerate_find_closest(int samplerate, uint32_t codec)
     const hb_rate_t * rate, * prev, * next;
 
     rate = prev = next = hb_audio_samplerate_get_next_for_codec(NULL, codec);
+
+    if (rate == NULL)
+    {
+        // This codec doesn't support any samplerate
+        return 0;
+    }
+
     while (rate != NULL && next->rate < samplerate)
     {
         rate = hb_audio_samplerate_get_next_for_codec(rate, codec);
@@ -4605,6 +4612,7 @@ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg)
     {
         /* This most likely means the client didn't call hb_audio_config_init
          * so bail. */
+        hb_audio_close(&audio);
         return 0;
     }
 
@@ -5196,7 +5204,12 @@ char * hb_strncat_dup( const char * s1, const char * s2, size_t n )
         strcpy( str, s1 );
     else
         strcpy( str, "" );
-    strncat( str, s2, n );
+
+    if (s2)
+    {
+        strncat( str, s2, n );
+    }
+
     return str;
 }
 
index 3f884b6c1d7593822787f4568edda1260bc6193f..28d260596ecad5bd8a3f13d1be10a91f6080f225 100644 (file)
@@ -1349,8 +1349,8 @@ static int decodeFrame( hb_work_object_t *w, packet_info_t * packet_info )
             reordered->pts          = packet_info->pts;
             reordered->scr_sequence = packet_info->scr_sequence;
             reordered->new_chap     = packet_info->new_chap;
+            reordered_hash_add(pv, reordered);
         }
-        reordered_hash_add(pv, reordered);
 
         // libav avcodec video decoder needs AVPacket flagged with
         // AV_PKT_FLAG_KEY for some codecs. For example, sequence of
index 27b7e23b08d4b369626ad0ebf38a62a7f9321731..10d9926d99c6316d98c14286226488e0972055a3 100644 (file)
@@ -1789,23 +1789,28 @@ static int decccInit( hb_work_object_t * w, hb_job_t * job )
                 {
                     retval = 1;
                 }
-                init_eia608(pv->cc608->data608);
+                else
+                {
+                    init_eia608(pv->cc608->data608);
+                }
             }
+
+            // When rendering subs, we need to push rollup subtitles out
+            // asap (instead of waiting for a completed line) so that we
+            // do not miss the frame that they should be rendered over.
+            pv->cc608->direct_rollup = w->subtitle->config.dest == RENDERSUB;
+        }
+
+        if (!retval)
+        {
+            // Generate generic SSA Script Info.
+            int height = job->title->geometry.height - job->crop[0] - job->crop[1];
+            int width = job->title->geometry.width - job->crop[2] - job->crop[3];
+            int safe_height = 0.8 * job->title->geometry.height;
+            hb_subtitle_add_ssa_header(w->subtitle, HB_FONT_MONO,
+                                       .08 * safe_height, width, height);
         }
     }
-    if (!retval)
-    {
-        // Generate generic SSA Script Info.
-        int height = job->title->geometry.height - job->crop[0] - job->crop[1];
-        int width = job->title->geometry.width - job->crop[2] - job->crop[3];
-        int safe_height = 0.8 * job->title->geometry.height;
-        hb_subtitle_add_ssa_header(w->subtitle, HB_FONT_MONO,
-                                   .08 * safe_height, width, height);
-    }
-    // When rendering subs, we need to push rollup subtitles out
-    // asap (instead of waiting for a completed line) so that we
-    // do not miss the frame that they should be rendered over.
-    pv->cc608->direct_rollup = w->subtitle->config.dest == RENDERSUB;
     return retval;
 }
 
@@ -1842,9 +1847,13 @@ static int decccWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
 static void decccClose( hb_work_object_t * w )
 {
     hb_work_private_t * pv = w->private_data;
-    general_608_close( pv->cc608 );
-    free( pv->cc608->data608 );
-    free( pv->cc608 );
+
+    if (pv)
+    {
+        general_608_close( pv->cc608 );
+        free( pv->cc608->data608 );
+        free( pv->cc608 );
+    }
     free( w->private_data );
 }
 
index 1ddb659ad30e6f56a7fd556eaf4203573ab8ffba..862c289da32fc29443fb2d15b1f6899d78278f35 100644 (file)
@@ -468,7 +468,6 @@ static void resample( uint8_t * dst, uint8_t * src, int dst_w, int src_w )
     if( dst_w < src_w )
     {
         // sample down
-        err = 0;
         sum = 0;
         val = 0;
         cnt = 0;
@@ -495,7 +494,6 @@ static void resample( uint8_t * dst, uint8_t * src, int dst_w, int src_w )
     else
     {
         // sample up
-        err = 0;
         err = dst_w / 2;
         src_x = 0;
         for( dst_x = 0; dst_x < dst_w; dst_x++ )
index 04ac22824d417b5bdb330a296c98b733b2f16ff9..4adab5cc06119f2f60a865e2cfe7304a09d6b390 100644 (file)
@@ -1055,7 +1055,8 @@ int apply_h264_level(const x264_api_t *api, x264_param_t *param,
             return -1;
         }
     }
-    else if(!strcasecmp(h264_level, hb_h264_level_names[0]))
+    else if(h264_level != NULL &&
+            !strcasecmp(h264_level, hb_h264_level_names[0]))
     {
         // "auto", do nothing
         return 0;
index 672810efb7014df2c7c1b1834b54204fdef8928d..9e6a2cc1fd92241e4d85cbfb805506a545079d1c 100644 (file)
@@ -607,10 +607,6 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job )
     }
     else if (job->pts_to_start != 0 || job->pts_to_stop != 0)
     {
-        range_dict = json_pack_ex(&error, 0, "{s:o, s:o, s:o}",
-            "Type",  hb_value_string("time"),
-            "Start", hb_value_int(job->pts_to_start),
-            "End",   hb_value_int(job->pts_to_stop));
         range_dict = hb_dict_init();
         hb_dict_set(source_dict, "Type", hb_value_string("time"));
         if (job->pts_to_start > 0)
index 196965bec92a2246d4f89e1cd17f5566b488f577..323173895bf3d25c5602341798be17c1746f8b88 100644 (file)
@@ -604,6 +604,24 @@ static int muxInit( hb_work_object_t * muxer, hb_job_t * job )
     int                i;
     hb_work_object_t * w;
 
+    /* Get a real muxer */
+    if( job->pass_id == HB_PASS_ENCODE || job->pass_id == HB_PASS_ENCODE_2ND )
+    {
+        switch( job->mux )
+        {
+            case HB_MUX_AV_MP4:
+            case HB_MUX_AV_MKV:
+                mux->m = hb_mux_avformat_init( job );
+                break;
+            default:
+                hb_error( "No muxer selected, exiting" );
+                free(mux);
+                *job->done_error = HB_ERROR_INIT;
+                *job->die = 1;
+                return -1;
+        }
+    }
+
     pv->list_work = hb_list_init();
 
     // The bit vectors must be allocated before hb_thread_init for the
@@ -623,21 +641,8 @@ static int muxInit( hb_work_object_t * muxer, hb_job_t * job )
     mux->interleave = 90000. * (double)job->vrate.den / job->vrate.num;
     mux->pts = mux->interleave;
 
-    /* Get a real muxer */
     if( job->pass_id == HB_PASS_ENCODE || job->pass_id == HB_PASS_ENCODE_2ND )
     {
-        switch( job->mux )
-        {
-        case HB_MUX_AV_MP4:
-        case HB_MUX_AV_MKV:
-            mux->m = hb_mux_avformat_init( job );
-            break;
-        default:
-            hb_error( "No muxer selected, exiting" );
-            *job->done_error = HB_ERROR_INIT;
-            *job->die = 1;
-            return -1;
-        }
         /* Create file, write headers */
         if( mux->m )
         {
index 578b6a27ada3c7be3816b133b099b888a8bff3b8..764ea5820dbe7428f85295c182394b8d552ef5b8 100644 (file)
@@ -1157,7 +1157,7 @@ int
 hb_validate_filter_preset(int filter_id, const char *preset, const char *tune,
                           const char *custom)
 {
-    if (preset == NULL && tune == NULL)
+    if (preset == NULL)
         return 1;
 
     int preset_count, tune_count;
index 22c35bbd93266b806e109e9185c278b974e7a227..726bc710bb9b59de438193215f98c7ab26638765 100644 (file)
@@ -227,13 +227,13 @@ int encCoreAudioInit(hb_work_object_t *w, hb_job_t *job, enum AAC_MODE mode)
         // get available bitrates
         AudioValueRange *bitrates;
         ssize_t bitrateCounts;
-        err = AudioConverterGetPropertyInfo(pv->converter,
-                                            kAudioConverterApplicableEncodeBitRates,
-                                            &tmpsiz, NULL);
+        AudioConverterGetPropertyInfo(pv->converter,
+                                      kAudioConverterApplicableEncodeBitRates,
+                                      &tmpsiz, NULL);
         bitrates = malloc(tmpsiz);
-        err = AudioConverterGetProperty(pv->converter,
-                                        kAudioConverterApplicableEncodeBitRates,
-                                        &tmpsiz, bitrates);
+        AudioConverterGetProperty(pv->converter,
+                                  kAudioConverterApplicableEncodeBitRates,
+                                  &tmpsiz, bitrates);
         bitrateCounts = tmpsiz / sizeof(AudioValueRange);
 
         // set bitrate
index 5840714ced3ab971241647c2876d2bbf82b158a7..710499024283918606730ad239db73d303430373 100644 (file)
@@ -921,7 +921,6 @@ static void add_subtitle_for_lang(hb_value_array_t *list, hb_title_t *title,
                                   subtitle_behavior_t *behavior)
 {
     int t;
-    t = find_subtitle_track(title, lang, 0);
     for (t = find_subtitle_track(title, lang, 0);
          t >= 0;
          t = behavior->one ? -1 : find_subtitle_track(title, lang, t + 1))
@@ -3698,6 +3697,12 @@ int hb_presets_add_path(char * path)
     {
         count++;
     }
+
+    if (count == 0)
+    {
+        return -1;
+    }
+
     files = malloc(count * sizeof(char*));
 
     // Find all regular files
index bfc5dbc04a4de381ae190bcc97c91619f2c536d3..326cb0e4b1357a374badcca15c298dd6fda14d8a 100644 (file)
@@ -813,6 +813,12 @@ static void prune_streams(hb_stream_t *d)
 hb_stream_t *
 hb_stream_open(hb_handle_t *h, char *path, hb_title_t *title, int scan)
 {
+    if (title == NULL)
+    {
+        hb_log("hb_stream_open: title is null");
+        return NULL;
+    }
+
     FILE *f = hb_fopen(path, "rb");
     if ( f == NULL )
     {
@@ -828,7 +834,7 @@ hb_stream_open(hb_handle_t *h, char *path, hb_title_t *title, int scan)
         return NULL;
     }
 
-    if( title && !( title->flags & HBTF_NO_IDR ) )
+    if (!(title->flags & HBTF_NO_IDR))
     {
         d->has_IDRs = 1;
     }
@@ -2899,10 +2905,10 @@ static int decode_PAT(const uint8_t *buf, hb_stream_t *stream)
                             }
                     }
 
-                    pos += 3 + section_len;
+//                    pos += 3 + section_len;
             }
 
-            tablepos = 0;
+//            tablepos = 0;
     }
     return 1;
 }