[x264-devel] param_parse: Check strdup() return value
Henrik Gramner
git at videolan.org
Sun Jul 26 22:26:29 CEST 2015
x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Tue Jun 23 22:47:53 2015 +0200| [d302526d5b97818f588b86f408f910924790242e] | committer: Anton Mitrofanov
param_parse: Check strdup() return value
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=d302526d5b97818f588b86f408f910924790242e
---
common/common.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/common/common.c b/common/common.c
index b32c5d3..5559d67 100644
--- a/common/common.c
+++ b/common/common.c
@@ -596,6 +596,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
{
char *c;
name_buf = strdup(name);
+ if( !name_buf )
+ return X264_PARAM_BAD_NAME;
while( (c = strchr( name_buf, '_' )) )
*c = '-';
name = name_buf;
@@ -618,20 +620,23 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
!strcasecmp(value, "auto") || atobool(value) ? x264_cpu_detect() : 0;
if( b_error )
{
- char *buf = strdup(value);
- char *tok, UNUSED *saveptr=NULL, *init;
- b_error = 0;
- p->cpu = 0;
- for( init=buf; (tok=strtok_r(init, ",", &saveptr)); init=NULL )
+ char *buf = strdup( value );
+ if( buf )
{
- for( i=0; 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;
+ char *tok, UNUSED *saveptr=NULL, *init;
+ b_error = 0;
+ 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++ );
+ p->cpu |= x264_cpu_names[i].flags;
+ if( !x264_cpu_names[i].flags )
+ b_error = 1;
+ }
+ free( buf );
+ if( (p->cpu&X264_CPU_SSSE3) && !(p->cpu&X264_CPU_SSE2_IS_SLOW) )
+ p->cpu |= X264_CPU_SSE2_IS_FAST;
}
- free( buf );
- if( (p->cpu&X264_CPU_SSSE3) && !(p->cpu&X264_CPU_SSE2_IS_SLOW) )
- p->cpu |= X264_CPU_SSE2_IS_FAST;
}
}
OPT("threads")
More information about the x264-devel
mailing list