Commit 14dd0a90 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt

avcodec/cbs: Avoid leaving the ... out in calls to variadic macros

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: 's avatarMark Thompson <sw@jkqxz.net>
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
parent b7d9507b
...@@ -550,12 +550,12 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) ...@@ -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 SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define fb(width, name) \ #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) \ #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 flag(name) fb(1, name)
#define su(width, name) \ #define su(width, name) \
xsu(width, name, current->name, 0) xsu(width, name, current->name, 0, )
#define fbs(width, name, subs, ...) \ #define fbs(width, name, subs, ...) \
xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) 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) ...@@ -568,7 +568,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
#define fixed(width, name, value) do { \ #define fixed(width, name, value) do { \
av_unused uint32_t fixed_value = value; \ 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) } while (0)
...@@ -623,9 +623,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) ...@@ -623,9 +623,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
#define delta_q(name) do { \ #define delta_q(name) do { \
uint8_t delta_coded; \ uint8_t delta_coded; \
int8_t delta_q; \ 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) \ if (delta_coded) \
xsu(1 + 6, name.delta_q, delta_q, 0); \ xsu(1 + 6, name.delta_q, delta_q, 0, ); \
else \ else \
delta_q = 0; \ delta_q = 0; \
current->name = delta_q; \ current->name = delta_q; \
...@@ -700,9 +700,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) ...@@ -700,9 +700,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
} while (0) } while (0)
#define delta_q(name) do { \ #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) \ if (current->name) \
xsu(1 + 6, name.delta_q, current->name, 0); \ xsu(1 + 6, name.delta_q, current->name, 0, ); \
} while (0) } while (0)
#define leb128(name) do { \ #define leb128(name) do { \
......
...@@ -250,18 +250,18 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, ...@@ -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 SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define u(width, name, range_min, range_max) \ #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) \ #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 flag(name) ub(1, name)
#define ue(name, range_min, range_max) \ #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) \ #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) \ #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) \ #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, ...) \ #define us(width, name, range_min, range_max, subs, ...) \
xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__) 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, ...@@ -280,7 +280,7 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define fixed(width, name, value) do { \ #define fixed(width, name, value) do { \
av_unused uint32_t fixed_value = value; \ 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) } while (0)
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define u(width, name, range_min, range_max) \ #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) \ #define us(width, name, sub, range_min, range_max) \
xu(width, name, range_min, range_max, 1, sub) xu(width, name, range_min, range_max, 1, sub)
......
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define ui(width, name) \ #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) \ #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, ...) \ #define uis(width, name, subs, ...) \
xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
#define uirs(width, name, subs, ...) \ #define uirs(width, name, subs, ...) \
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
bit("marker_bit", 1) bit("marker_bit", 1)
#define bit(string, value) do { \ #define bit(string, value) do { \
av_unused uint32_t bit = value; \ av_unused uint32_t bit = value; \
xuia(1, string, bit, value, value, 0); \ xuia(1, string, bit, value, value, 0, ); \
} while (0) } while (0)
......
...@@ -253,15 +253,14 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, ...@@ -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 SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define f(width, name) \ #define f(width, name) \
xf(width, name, current->name, 0) xf(width, name, current->name, 0, )
#define s(width, name) \ #define s(width, name) \
xs(width, name, current->name, 0) xs(width, name, current->name, 0, )
#define fs(width, name, subs, ...) \ #define fs(width, name, subs, ...) \
xf(width, name, current->name, subs, __VA_ARGS__) xf(width, name, current->name, subs, __VA_ARGS__)
#define ss(width, name, subs, ...) \ #define ss(width, name, subs, ...) \
xs(width, name, current->name, subs, __VA_ARGS__) xs(width, name, current->name, subs, __VA_ARGS__)
#define READ #define READ
#define READWRITE read #define READWRITE read
#define RWContext GetBitContext #define RWContext GetBitContext
...@@ -295,9 +294,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, ...@@ -295,9 +294,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define delta_q(name) do { \ #define delta_q(name) do { \
uint8_t delta_coded; \ uint8_t delta_coded; \
int8_t delta_q; \ int8_t delta_q; \
xf(1, name.delta_coded, delta_coded, 0); \ xf(1, name.delta_coded, delta_coded, 0, ); \
if (delta_coded) \ if (delta_coded) \
xs(4, name.delta_q, delta_q, 0); \ xs(4, name.delta_q, delta_q, 0, ); \
else \ else \
delta_q = 0; \ delta_q = 0; \
current->name = delta_q; \ current->name = delta_q; \
...@@ -366,9 +365,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, ...@@ -366,9 +365,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
} while (0) } while (0)
#define delta_q(name) do { \ #define delta_q(name) do { \
xf(1, name.delta_coded, !!current->name, 0); \ xf(1, name.delta_coded, !!current->name, 0, ); \
if (current->name) \ if (current->name) \
xs(4, name.delta_q, current->name, 0); \ xs(4, name.delta_q, current->name, 0, ); \
} while (0) } while (0)
#define prob(name, subs, ...) do { \ #define prob(name, subs, ...) do { \
......
...@@ -19,23 +19,11 @@ ...@@ -19,23 +19,11 @@
static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
VP9RawFrameHeader *current) 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; int err;
xf(8, frame_sync_byte_0, frame_sync_byte_0, 0); fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
xf(8, frame_sync_byte_1, frame_sync_byte_1, 0); fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
xf(8, frame_sync_byte_2, frame_sync_byte_2, 0); fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
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;
}
return 0; return 0;
} }
...@@ -396,9 +384,8 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, ...@@ -396,9 +384,8 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw) static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
{ {
int err; int err;
av_unused int zero = 0;
while (byte_alignment(rw) != 0) while (byte_alignment(rw) != 0)
xf(1, zero_bit, zero, 0); fixed(1, zero_bit, 0);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment