]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/cbs: Avoid leaving the ... out in calls to variadic macros
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 22 Mar 2020 19:34:21 +0000 (20:34 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 12 Apr 2020 21:23:49 +0000 (23:23 +0200)
According to C99, there has to be at least one argument for every ...
in a variadic function-like macro. In practice most (all?) compilers also
allow to leave it completely out, but it is nevertheless required: In a
variadic macro "there shall be more arguments in the invocation than there
are parameters in the macro definition (excluding the ...)." (C99,
6.10.3.4).

CBS (not the framework itself, but the macros used in the
cbs_*_syntax_template.c files) relies on the compiler allowing to leave
a variadic macro argument out. This leads to warnings when compiling in
-pedantic mode, e.g. "warning: must specify at least one argument for
'...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]"
from Clang.

Most of these warnings can be easily avoided: The syntax_templates
mostly contain helper macros that expand to more complex variadic macros
and these helper macros often omit an argument for the .... Modifying
them to always expand to complex macros with an empty argument for the
... at the end fixes most of these warnings: The number of warnings went
down from 400 to 0 for cbs_av1, from 1114 to 32 for cbs_h2645, from 38 to
0 for cbs_jpeg, from 166 to 0 for cbs_mpeg2 and from 110 to 8 for cbs_vp9.

These eight remaining warnings for cbs_vp9 have been fixed by switching
to another macro in cbs_vp9_syntax_template: The fixed values for the
sync bytes as well as the trailing bits for byte-alignment are now read
via the fixed() macro (this also adds a check to ensure that trailing
bits are indeed zero as they have to be).

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/cbs_av1.c
libavcodec/cbs_h2645.c
libavcodec/cbs_jpeg.c
libavcodec/cbs_mpeg2.c
libavcodec/cbs_vp9.c
libavcodec/cbs_vp9_syntax_template.c

index 16eb7143b64f6e3eecac8e29d117eddf2986f119..fc228086c297c200cb7aa49e70f89f2824955732 100644 (file)
@@ -550,12 +550,12 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
 #define fb(width, name) \
-        xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
+        xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
 #define fc(width, name, range_min, range_max) \
-        xf(width, name, current->name, range_min, range_max, 0)
+        xf(width, name, current->name, range_min, range_max, 0)
 #define flag(name) fb(1, name)
 #define su(width, name) \
-        xsu(width, name, current->name, 0)
+        xsu(width, name, current->name, 0)
 
 #define fbs(width, name, subs, ...) \
         xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
@@ -568,7 +568,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 
 #define fixed(width, name, value) do { \
         av_unused uint32_t fixed_value = value; \
-        xf(width, name, fixed_value, value, value, 0); \
+        xf(width, name, fixed_value, value, value, 0); \
     } while (0)
 
 
@@ -623,9 +623,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 #define delta_q(name) do { \
         uint8_t delta_coded; \
         int8_t delta_q; \
-        xf(1, name.delta_coded, delta_coded, 0, 1, 0); \
+        xf(1, name.delta_coded, delta_coded, 0, 1, 0); \
         if (delta_coded) \
-            xsu(1 + 6, name.delta_q, delta_q, 0); \
+            xsu(1 + 6, name.delta_q, delta_q, 0); \
         else \
             delta_q = 0; \
         current->name = delta_q; \
@@ -700,9 +700,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
     } while (0)
 
 #define delta_q(name) do { \
-        xf(1, name.delta_coded, current->name != 0, 0, 1, 0); \
+        xf(1, name.delta_coded, current->name != 0, 0, 1, 0); \
         if (current->name) \
-            xsu(1 + 6, name.delta_q, current->name, 0); \
+            xsu(1 + 6, name.delta_q, current->name, 0); \
     } while (0)
 
 #define leb128(name) do { \
index 7a4eecf439045c03de5a3d379c00d32b4169ece1..d42073cc5a7f7d7a229861de183809b2a8fc97c2 100644 (file)
@@ -250,18 +250,18 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
 #define u(width, name, range_min, range_max) \
-        xu(width, name, current->name, range_min, range_max, 0)
+        xu(width, name, current->name, range_min, range_max, 0)
 #define ub(width, name) \
-        xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
+        xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
 #define flag(name) ub(1, name)
 #define ue(name, range_min, range_max) \
-        xue(name, current->name, range_min, range_max, 0)
+        xue(name, current->name, range_min, range_max, 0)
 #define i(width, name, range_min, range_max) \
-        xi(width, name, current->name, range_min, range_max, 0)
+        xi(width, name, current->name, range_min, range_max, 0)
 #define ib(width, name) \
-        xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0)
+        xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0)
 #define se(name, range_min, range_max) \
-        xse(name, current->name, range_min, range_max, 0)
+        xse(name, current->name, range_min, range_max, 0)
 
 #define us(width, name, range_min, range_max, subs, ...) \
         xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
@@ -280,7 +280,7 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
 #define fixed(width, name, value) do { \
         av_unused uint32_t fixed_value = value; \
-        xu(width, name, fixed_value, value, value, 0); \
+        xu(width, name, fixed_value, value, value, 0); \
     } while (0)
 
 
index 89512a26bbf190591f7cc51d0b18d202d1b25017..4ff04ae52db713f1a1009cd7d512657ca08c1cb0 100644 (file)
@@ -34,7 +34,7 @@
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
 #define u(width, name, range_min, range_max) \
-    xu(width, name, range_min, range_max, 0)
+    xu(width, name, range_min, range_max, 0)
 #define us(width, name, sub, range_min, range_max) \
     xu(width, name, range_min, range_max, 1, sub)
 
index 0e5d08ecbf6346099955227b50273825bb179c1a..97f7889cbb87a668dda1d8ca1df6e35f992080c9 100644 (file)
@@ -41,9 +41,9 @@
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
 #define ui(width, name) \
-        xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
+        xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
 #define uir(width, name) \
-        xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0)
+        xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0)
 #define uis(width, name, subs, ...) \
         xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
 #define uirs(width, name, subs, ...) \
@@ -57,7 +57,7 @@
         bit("marker_bit", 1)
 #define bit(string, value) do { \
         av_unused uint32_t bit = value; \
-        xuia(1, string, bit, value, value, 0); \
+        xuia(1, string, bit, value, value, 0); \
     } while (0)
 
 
index ec82f11c768578b27a3a9d8fbcdbb27c9e90034d..eef603bfb27e78bcb5c1f8251b51d53d52e394b7 100644 (file)
@@ -253,15 +253,14 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
 #define f(width, name) \
-        xf(width, name, current->name, 0)
+        xf(width, name, current->name, 0)
 #define s(width, name) \
-        xs(width, name, current->name, 0)
+        xs(width, name, current->name, 0)
 #define fs(width, name, subs, ...) \
         xf(width, name, current->name, subs, __VA_ARGS__)
 #define ss(width, name, subs, ...) \
         xs(width, name, current->name, subs, __VA_ARGS__)
 
-
 #define READ
 #define READWRITE read
 #define RWContext GetBitContext
@@ -295,9 +294,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define delta_q(name) do { \
         uint8_t delta_coded; \
         int8_t delta_q; \
-        xf(1, name.delta_coded, delta_coded, 0); \
+        xf(1, name.delta_coded, delta_coded, 0); \
         if (delta_coded) \
-            xs(4, name.delta_q, delta_q, 0); \
+            xs(4, name.delta_q, delta_q, 0); \
         else \
             delta_q = 0; \
         current->name = delta_q; \
@@ -366,9 +365,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
     } while (0)
 
 #define delta_q(name) do { \
-        xf(1, name.delta_coded, !!current->name, 0); \
+        xf(1, name.delta_coded, !!current->name, 0); \
         if (current->name) \
-            xs(4, name.delta_q, current->name, 0); \
+            xs(4, name.delta_q, current->name, 0); \
     } while (0)
 
 #define prob(name, subs, ...) do { \
index 125eb0258957bb1b725cabf095661211d71d371b..2f08eccf180e93b619f448c62c58b3702bb28616 100644 (file)
 static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
                                  VP9RawFrameHeader *current)
 {
-    uint8_t frame_sync_byte_0 = VP9_FRAME_SYNC_0;
-    uint8_t frame_sync_byte_1 = VP9_FRAME_SYNC_1;
-    uint8_t frame_sync_byte_2 = VP9_FRAME_SYNC_2;
     int err;
 
-    xf(8, frame_sync_byte_0, frame_sync_byte_0, 0);
-    xf(8, frame_sync_byte_1, frame_sync_byte_1, 0);
-    xf(8, frame_sync_byte_2, frame_sync_byte_2, 0);
-
-    if (frame_sync_byte_0 != VP9_FRAME_SYNC_0 ||
-        frame_sync_byte_1 != VP9_FRAME_SYNC_1 ||
-        frame_sync_byte_2 != VP9_FRAME_SYNC_2) {
-        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid frame sync code: "
-               "%02x %02x %02x.\n", frame_sync_byte_0,
-               frame_sync_byte_1, frame_sync_byte_2);
-        return AVERROR_INVALIDDATA;
-    }
+    fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
+    fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
+    fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
 
     return 0;
 }
@@ -396,9 +384,8 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
 {
     int err;
-    av_unused int zero = 0;
     while (byte_alignment(rw) != 0)
-        xf(1, zero_bit, zero, 0);
+        fixed(1, zero_bit, 0);
 
     return 0;
 }