[FFmpeg-devel] [PATCH] parse_options(): Avoid passing NULL as a string arg to fprintf

Jeff Downs heydowns at somuchpressure.net
Thu Jun 23 20:57:45 CEST 2011

I recently restored FATE testing on SPARC/Solaris.  One test is presently 
failing, where ffmpeg crashes when given the argument -pix_fmts.

The crash occurs due to arg being NULL in the fprintf mentioned in the 
patch below.  The patch fixes the specific symptom, and seems to be a 
good idea anyway as in the general case it appears that arg can be NULL.  

However this doesn't fix the underlying problem that when processing 
-pix_fmts (and others like it), the error case is being executed to begin 

This is because several of the arg processing functions, the one for 
-pix_fmts included, are accessed via function pointer int (*fp)(const char 
*, const char *) but, in reality, are functions declared & implemented as 
void f(void).
On sparc, executing these with the expectation of returning int does not 
yield a 0 return (as it apparently does on other platforms).

I was going to send patches to fix this, too, but that would require 
changing all the arg processing functions to match the pointer signature 
and thought that it best to put the problem out there and collect any 
comments/input before working on such a large change.

Note that most of the problematic functions would have to be changed to 
both take args (where they don't presently, and hence the args would be 
dummy) and to return a value (fixed 0) to fix this to be "proper". Input 


 cmdutils.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index cd6d133..f538d98 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -281,7 +281,7 @@ unknown_opt:
                 *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
             } else if (po->u.func_arg) {
                 if (po->u.func_arg(opt, arg) < 0) {
-                    fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
+                    fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg ? arg : "[null]", opt);

More information about the ffmpeg-devel mailing list