[FFmpeg-soc] [soc]: r556 - in libavfilter: avfilter.c avfilter.h

koorogi subversion at mplayerhq.hu
Mon Jul 30 17:53:33 CEST 2007


Author: koorogi
Date: Mon Jul 30 17:53:33 2007
New Revision: 556

Log:
Fix some potential segfaults.


Modified:
   libavfilter/avfilter.c
   libavfilter/avfilter.h

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Mon Jul 30 17:53:33 2007
@@ -64,7 +64,10 @@ AVFilterPicRef *avfilter_default_get_vid
 
 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
 {
-    AVFilterLink *out = link->dst->outputs[0];
+    AVFilterLink *out = NULL;
+
+    if(link->dst->output_count)
+        out = link->dst->outputs[0];
 
     link->cur_pic = picref;
 
@@ -77,7 +80,10 @@ void avfilter_default_start_frame(AVFilt
 
 void avfilter_default_end_frame(AVFilterLink *link)
 {
-    AVFilterLink *out = link->dst->outputs[0];
+    AVFilterLink *out = NULL;
+
+    if(link->dst->output_count)
+        out = link->dst->outputs[0];
 
     avfilter_unref_pic(link->cur_pic);
     link->cur_pic = NULL;
@@ -110,8 +116,15 @@ void avfilter_unref_pic(AVFilterPicRef *
  * the implementation of one input one output video filters */
 static int default_config_output_link(AVFilterLink *link)
 {
+    if(link->src->input_count && link->src->inputs[0]) {
     link->w = link->src->inputs[0]->w;
     link->h = link->src->inputs[0]->h;
+    } else {
+        /* XXX: any non-simple filter which would cause this branch to be taken
+         * really should implement its own config_props() for this link. */
+        link->w =
+        link->h = 0;
+    }
 
     return 0;
 }
@@ -121,7 +134,12 @@ static int default_config_output_link(AV
  * the implementation of one input one output video filters */
 static int *default_query_output_formats(AVFilterLink *link)
 {
+    if(link->src->input_count && link->src->inputs[0])
     return avfilter_make_format_list(1, link->src->inputs[0]->format);
+    else
+        /* XXX: any non-simple filter which would cause this branch to be taken
+         * really should implement its own query_formats() for this link */
+        return avfilter_make_format_list(0);
 }
 
 int avfilter_link(AVFilterContext *src, unsigned srcpad,
@@ -130,7 +148,8 @@ int avfilter_link(AVFilterContext *src, 
     AVFilterLink *link;
     int *fmts[2], i, j;
 
-    if(src->outputs[srcpad] || dst->inputs[dstpad])
+    if(src->output_count <= srcpad || dst->input_count <= dstpad ||
+       src->outputs[srcpad]        || dst->inputs[dstpad])
         return -1;
 
     src->outputs[srcpad] =
@@ -227,6 +246,9 @@ void avfilter_end_frame(AVFilterLink *li
 
 void avfilter_draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
 {
+    if(!link->dst->filter->inputs[link->dstpad].draw_slice)
+        return;
+
     link->dst->filter->inputs[link->dstpad].draw_slice(link, data, y, h);
 }
 
@@ -296,10 +318,13 @@ AVFilterContext *avfilter_create(AVFilte
     ret->av_class->item_name = filter_name;
     ret->filter   = filter;
     ret->name     = inst_name ? av_strdup(inst_name) : NULL;
-    ret->inputs   = av_mallocz(sizeof(AVFilterLink*) * pad_count(filter->inputs));
-    ret->outputs  = av_mallocz(sizeof(AVFilterLink*) * pad_count(filter->outputs));
     ret->priv     = av_mallocz(filter->priv_size);
 
+    ret->input_count  = pad_count(filter->inputs);
+    ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
+    ret->output_count = pad_count(filter->outputs);
+    ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
+
     return ret;
 }
 

Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h	(original)
+++ libavfilter/avfilter.h	Mon Jul 30 17:53:33 2007
@@ -184,7 +184,10 @@ struct AVFilterContext
 
     char *name;
 
+    unsigned input_count;
     AVFilterLink **inputs;
+
+    unsigned output_count;
     AVFilterLink **outputs;
 
     void *priv;



More information about the FFmpeg-soc mailing list