[x264-devel] Silence various static analyzer warnings

Henrik Gramner git at videolan.org
Wed Aug 19 21:16:13 CEST 2015


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Wed Jul 29 19:30:41 2015 +0200| [f04062e6380cbe10453dab33a3575c373e63ff9b] | committer: Anton Mitrofanov

Silence various static analyzer warnings

Those are false positives, but it doesn't hurt to get rid of them.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=f04062e6380cbe10453dab33a3575c373e63ff9b
---

 common/common.c   |   12 +++++++-----
 common/common.h   |    5 ++---
 encoder/encoder.c |    9 ++++-----
 encoder/me.c      |    5 +++--
 input/avs.c       |    7 +++----
 5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/common/common.c b/common/common.c
index 273334a..6999a00 100644
--- a/common/common.c
+++ b/common/common.c
@@ -582,7 +582,6 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
     int errortype = X264_PARAM_BAD_VALUE;
     int name_was_bool;
     int value_was_null = !value;
-    int i;
 
     if( !name )
         return X264_PARAM_BAD_NAME;
@@ -603,10 +602,11 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         name = name_buf;
     }
 
-    if( (!strncmp( name, "no-", 3 ) && (i = 3)) ||
-        (!strncmp( name, "no", 2 ) && (i = 2)) )
+    if( !strncmp( name, "no", 2 ) )
     {
-        name += i;
+        name += 2;
+        if( name[0] == '-' )
+            name++;
         value = atobool(value) ? "false" : "true";
     }
     name_was_bool = 0;
@@ -628,7 +628,9 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
                 p->cpu = 0;
                 for( init=buf; (tok=strtok_r(init, ",", &saveptr)); init=NULL )
                 {
-                    for( i=0; x264_cpu_names[i].flags && strcasecmp(tok, x264_cpu_names[i].name); i++ );
+                    int i = 0;
+                    while( x264_cpu_names[i].flags && strcasecmp(tok, x264_cpu_names[i].name) )
+                        i++;
                     p->cpu |= x264_cpu_names[i].flags;
                     if( !x264_cpu_names[i].flags )
                         b_error = 1;
diff --git a/common/common.h b/common/common.h
index 7d5e5fb..9cda187 100644
--- a/common/common.h
+++ b/common/common.h
@@ -895,9 +895,6 @@ struct x264_t
     /* stats */
     struct
     {
-        /* Current frame stats */
-        x264_frame_stat_t frame;
-
         /* Cumulated stats */
 
         /* per slice info */
@@ -927,6 +924,8 @@ struct x264_t
         /* num p-frames weighted */
         int     i_wpred[2];
 
+        /* Current frame stats */
+        x264_frame_stat_t frame;
     } stat;
 
     /* 0 = luma 4x4, 1 = luma 8x8, 2 = chroma 4x4, 3 = chroma 8x8 */
diff --git a/encoder/encoder.c b/encoder/encoder.c
index fd77f48..79997b9 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1010,9 +1010,9 @@ static int x264_validate_parameters( x264_t *h, int b_open )
         h->param.i_fps_num = 25;
         h->param.i_fps_den = 1;
     }
-    float fps = (float) h->param.i_fps_num / h->param.i_fps_den;
+    float fps = (float)h->param.i_fps_num / h->param.i_fps_den;
     if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO )
-        h->param.i_keyint_min = X264_MIN( h->param.i_keyint_max / 10, fps );
+        h->param.i_keyint_min = X264_MIN( h->param.i_keyint_max / 10, (int)fps );
     h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );
     h->param.rc.i_lookahead = x264_clip3( h->param.rc.i_lookahead, 0, X264_LOOKAHEAD_MAX );
     {
@@ -3043,9 +3043,8 @@ static void x264_thread_sync_context( x264_t *dst, x264_t *src )
 
 static void x264_thread_sync_stat( x264_t *dst, x264_t *src )
 {
-    if( dst == src )
-        return;
-    memcpy( &dst->stat.i_frame_count, &src->stat.i_frame_count, sizeof(dst->stat) - sizeof(dst->stat.frame) );
+    if( dst != src )
+        memcpy( &dst->stat, &src->stat, offsetof(x264_t, stat.frame) - offsetof(x264_t, stat) );
 }
 
 static void *x264_slices_write( x264_t *h )
diff --git a/encoder/me.c b/encoder/me.c
index d34644d..8096568 100644
--- a/encoder/me.c
+++ b/encoder/me.c
@@ -707,10 +707,11 @@ void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc,
                 sad_thresh = bsad*sad_thresh>>3;
                 while( nmvsad > limit*2 && sad_thresh > bsad )
                 {
-                    int i;
+                    int i = 0;
                     // halve the range if the domain is too large... eh, close enough
                     sad_thresh = (sad_thresh + bsad) >> 1;
-                    for( i = 0; i < nmvsad && mvsads[i].sad <= sad_thresh; i++ );
+                    while( i < nmvsad && mvsads[i].sad <= sad_thresh )
+                        i++;
                     for( int j = i; j < nmvsad; j++ )
                     {
                         uint32_t sad;
diff --git a/input/avs.c b/input/avs.c
index 3e4c8e5..71670b6 100644
--- a/input/avs.c
+++ b/input/avs.c
@@ -283,8 +283,8 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
                        "input clip height not divisible by 4 (%dx%d)\n", vi->width, vi->height )
         FAIL_IF_ERROR( (opt->output_csp == X264_CSP_I420 || info->interlaced) && (vi->height&1),
                        "input clip height not divisible by 2 (%dx%d)\n", vi->width, vi->height )
-        char conv_func[14] = { "ConvertTo" };
-        strcat( conv_func, csp );
+        char conv_func[14];
+        snprintf( conv_func, sizeof(conv_func), "ConvertTo%s", csp );
         char matrix[7] = "";
         int arg_count = 2;
         /* if doing a rgb <-> yuv conversion then range is handled via 'matrix'. though it's only supported in 2.56+ */
@@ -292,8 +292,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
         {
             // if converting from yuv, then we specify the matrix for the input, otherwise use the output's.
             int use_pc_matrix = avs_is_yuv( vi ) ? opt->input_range == RANGE_PC : opt->output_range == RANGE_PC;
-            strcpy( matrix, use_pc_matrix ? "PC." : "Rec" );
-            strcat( matrix, "601" ); /* FIXME: use correct coefficients */
+            snprintf( matrix, sizeof(matrix), "%s601", use_pc_matrix ? "PC." : "Rec" ); /* FIXME: use correct coefficients */
             arg_count++;
             // notification that the input range has changed to the desired one
             opt->input_range = opt->output_range;



More information about the x264-devel mailing list