[FFmpeg-devel] [PATCH 1/9] Change the signature of parse_link_name() to make it return an error code.

Stefano Sabatini stefano.sabatini-lala
Fri Nov 5 18:20:25 CET 2010


---
 libavfilter/graphparser.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index fb70805..caaa505 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -54,31 +54,36 @@ static int link_filter(AVFilterContext *src, int srcpad,
 /**
  * Parse the name of a link, which has the format "[linkname]".
  *
- * @return a pointer (that need to be freed after use) to the name
- * between parenthesis
+ * @param link_name put here a pointer (that need to be freed after
+ * use) to the name between parenthesis, or NULL in case of failure
+ * @return 0 in case of success, or a negative AVERROR code in case of
+ * failure
  */
-static char *parse_link_name(const char **buf, AVClass *log_ctx)
+static int parse_link_name(char **link_name, const char **buf, AVClass *log_ctx)
 {
     const char *start = *buf;
-    char *name;
+    int ret = 0;
     (*buf)++;
 
-    name = av_get_token(buf, "]");
+    *link_name = av_get_token(buf, "]");
 
-    if (!name[0]) {
+    if (!*link_name[0]) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Bad (empty?) label found in the following: \"%s\".\n", start);
+        ret = AVERROR(EINVAL);
         goto fail;
     }
 
     if (*(*buf)++ != ']') {
         av_log(log_ctx, AV_LOG_ERROR,
                "Mismatched '[' found in the following: \"%s\".\n", start);
+        ret = AVERROR(EINVAL);
     fail:
-        av_freep(&name);
+        av_freep(link_name);
+        return ret;
     }
 
-    return name;
+    return 0;
 }
 
 /**
@@ -241,14 +246,14 @@ static int link_filter_inouts(AVFilterContext *filter,
 static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
                         AVFilterInOut **open_outputs, AVClass *log_ctx)
 {
-    int pad = 0;
+    int pad = 0, ret;
 
     while (**buf == '[') {
-        char *name = parse_link_name(buf, log_ctx);
+        char *name;
         AVFilterInOut *match;
 
-        if (!name)
-            return -1;
+        if ((ret = parse_link_name(&name, buf, log_ctx)) < 0)
+            return ret;
 
         /* First check if the label is not in the open_outputs list */
         match = extract_inout(name, open_outputs);
@@ -275,17 +280,16 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
                          AVFilterInOut **open_inputs,
                          AVFilterInOut **open_outputs, AVClass *log_ctx)
 {
-    int pad = 0;
+    int pad = 0, ret;
 
     while (**buf == '[') {
-        char *name = parse_link_name(buf, log_ctx);
         AVFilterInOut *match;
-
         AVFilterInOut *input = *curr_inputs;
-        *curr_inputs = (*curr_inputs)->next;
+        char *name;
 
-        if (!name)
-            return -1;
+        *curr_inputs = (*curr_inputs)->next;
+        if ((ret = parse_link_name(&name, buf, log_ctx)) < 0)
+            return ret;
 
         /* First check if the label is not in the open_inputs list */
         match = extract_inout(name, open_inputs);
-- 
1.7.1




More information about the ffmpeg-devel mailing list