diff mbox series

[FFmpeg-devel,3/5] lavfi/(a)format: factor finding the delimiter

Message ID 20220302184023.285022-3-george@nsup.org
State New
Headers show
Series [FFmpeg-devel,1/5] lavfi/graphdump: add plain listing output | expand

Commit Message

Nicolas George March 2, 2022, 6:40 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/af_aformat.c | 8 +++++---
 libavfilter/internal.h   | 9 +++++++++
 libavfilter/vf_format.c  | 9 ++++-----
 3 files changed, 18 insertions(+), 8 deletions(-)


Same as sent earlier today.
diff mbox series

Patch

diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index d2599431dc..0cdea2220f 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -65,10 +65,12 @@  do {                                                                        \
     char *next, *cur = str;                                                 \
     int ret;                                                                \
                                                                             \
-    while (cur) {                                                           \
+    if (!cur)                                                               \
+        break;                                                              \
+    while (*cur) {                                                          \
         type fmt;                                                           \
-        next = strchr(cur, '|');                                            \
-        if (next)                                                           \
+        next = ff_formats_list_find_delimiter(cur);                         \
+        if (*next)                                                          \
             *next++ = 0;                                                    \
                                                                             \
         if ((fmt = get_fmt(cur)) == none) {                                 \
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 53883101a8..74037e5eb9 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -405,4 +405,13 @@  int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
 int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
                              int default_pool_size);
 
+/**
+ * Find the next delimiter in a string of formats.
+ * The delimiter is '|' or the end of the string.
+ */
+static inline char *ff_formats_list_find_delimiter(const char *str)
+{
+    return (char *)str + strcspn(str, "|");
+}
+
 #endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c
index c78acbf87b..8940a0e427 100644
--- a/libavfilter/vf_format.c
+++ b/libavfilter/vf_format.c
@@ -67,10 +67,9 @@  static av_cold int init(AVFilterContext *ctx)
 
     /* count the formats */
     cur = s->pix_fmts;
-    while ((cur = strchr(cur, '|'))) {
+    while (*(cur = ff_formats_list_find_delimiter(cur))) {
         nb_formats++;
-        if (*cur)
-            cur++;
+        cur++;
     }
 
     s->formats = av_malloc_array(nb_formats + 1, sizeof(*s->formats));
@@ -80,8 +79,8 @@  static av_cold int init(AVFilterContext *ctx)
     /* parse the list of formats */
     cur = s->pix_fmts;
     for (i = 0; i < nb_formats; i++) {
-        sep = strchr(cur, '|');
-        if (sep)
+        sep = ff_formats_list_find_delimiter(cur);
+        if (*sep)
             *sep++ = 0;
 
         if ((ret = ff_parse_pixel_format(&s->formats[i], cur, ctx)) < 0)