From: Soft Works <softworkz@hotmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v4 06/10] libavformat/asfdec: fix macro definition and use
Date: Mon, 16 May 2022 22:03:02 +0000
Message-ID: <DM8P223MB0365D7ECAD619B7CEE7FE390BACF9@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <DB6PR0101MB221474AA5568B0CD49B900D48FCF9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Andreas Rheinhardt
> Sent: Monday, May 16, 2022 10:49 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v4 06/10] libavformat/asfdec: fix
> macro definition and use
>
> Soft Works:
> >
> >
> >> -----Original Message-----
> >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> >> Andreas Rheinhardt
> >> Sent: Sunday, May 15, 2022 8:12 PM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH v4 06/10] libavformat/asfdec:
> fix
> >> macro definition and use
> >>
> >> softworkz:
> >>> From: softworkz <softworkz@hotmail.com>
> >>>
> >>> Signed-off-by: softworkz <softworkz@hotmail.com>
> >>> ---
> >>> libavformat/asfdec_f.c | 24 ++++++++++++------------
> >>> 1 file changed, 12 insertions(+), 12 deletions(-)
> >>>
> >>> diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
> >>> index 81a29f99d5..91c3874ac7 100644
> >>> --- a/libavformat/asfdec_f.c
> >>> +++ b/libavformat/asfdec_f.c
> >>> @@ -906,21 +906,21 @@ static int asf_read_header(AVFormatContext
> *s)
> >>> }
> >>>
> >>> #define DO_2BITS(bits, var, defval) \
> >>> - switch (bits & 3) { \
> >>> + switch ((bits) & 3) { \
> >>> case 3: \
> >>> - var = avio_rl32(pb); \
> >>> + (var) = avio_rl32(pb); \
> >>> rsize += 4; \
> >>> break; \
> >>> case 2: \
> >>> - var = avio_rl16(pb); \
> >>> + (var) = avio_rl16(pb); \
> >>> rsize += 2; \
> >>> break; \
> >>> case 1: \
> >>> - var = avio_r8(pb); \
> >>> + (var) = avio_r8(pb); \
> >>> rsize++; \
> >>> break; \
> >>> default: \
> >>> - var = defval; \
> >>> + (var) = (defval); \
> >>> break; \
> >>> }
> >>>
> >>> @@ -1003,9 +1003,9 @@ static int asf_get_packet(AVFormatContext
> *s,
> >> AVIOContext *pb)
> >>> asf->packet_flags = c;
> >>> asf->packet_property = d;
> >>>
> >>> - DO_2BITS(asf->packet_flags >> 5, packet_length, s-
> >>> packet_size);
> >>> - DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence
> >> ignored
> >>> - DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding
> length
> >>> + DO_2BITS(asf->packet_flags >> 5, packet_length, s-
> >packet_size)
> >>> + DO_2BITS(asf->packet_flags >> 1, padsize, 0) // sequence
> >> ignored
> >>> + DO_2BITS(asf->packet_flags >> 3, padsize, 0) // padding
> length
> >>>
> >>> // the following checks prevent overflows and infinite loops
> >>> if (!packet_length || packet_length >= (1U << 29)) {
> >>> @@ -1066,9 +1066,9 @@ static int
> >> asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
> >>> asf->stream_index = asf->asfid2avid[num & 0x7f];
> >>> asfst = &asf->streams[num & 0x7f];
> >>> // sequence should be ignored!
> >>> - DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
> >>> - DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset,
> >> 0);
> >>> - DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
> >>> + DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0)
> >>> + DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset,
> 0)
> >>> + DO_2BITS(asf->packet_property, asf->packet_replic_size, 0)
> >>> av_log(asf, AV_LOG_TRACE, "key:%d stream:%d seq:%d offset:%d
> >> replic_size:%d num:%X packet_property %X\n",
> >>> asf->packet_key_frame, asf->stream_index, asf-
> >>> packet_seq,
> >>> asf->packet_frag_offset, asf->packet_replic_size,
> num,
> >> asf->packet_property);
> >>> @@ -1144,7 +1144,7 @@ static int
> >> asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
> >>> return AVERROR_INVALIDDATA;
> >>> }
> >>> if (asf->packet_flags & 0x01) {
> >>> - DO_2BITS(asf->packet_segsizetype >> 6, asf-
> >>> packet_frag_size, 0); // 0 is illegal
> >>> + DO_2BITS(asf->packet_segsizetype >> 6, asf-
> >>> packet_frag_size, 0) // 0 is illegal
> >>> if (rsize > asf->packet_size_left) {
> >>> av_log(s, AV_LOG_ERROR, "packet_replic_size is
> >> invalid\n");
> >>> return AVERROR_INVALIDDATA;
> >>
> >> While protecting macro arguments is good, it is not really a "fix"
> >> unless current usage is buggy.
> >
> > Ok, I will rephrase the commit message.
> >
> >> Which it isn't here, because >> has higher precedence than &.
> >
> > Could you explain which change you are referring to?
> >
>
> Putting "bits" in parentheses. It doesn't change anything, because >>
> has higher precedence than &.
Ah, that's what you mean. I didn't even look at the usages of
the macro, because I think a macro should be safe intrinsically,
not only based on its current usages.
Actually this had also caught my attention due to a clang warning:
https://releases.llvm.org/13.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/bugprone-macro-parentheses.html
> > All this patch does is to put macro variables in brackets
> > and remove semicolons..
> >
> >> Furthermore I am not really sure whether removing the ';' is even
> >> something worthwhile; they are surely unnecessary (being null
> >> statements), but does this matter?
> >
> > It causes a warning
> >
> >
> https://releases.llvm.org/13.0.0/tools/clang/docs/DiagnosticsReference
> .html#wextra-semi-stmt
> >
>
> I don't receive this warning despite using Clang 13.0. Do you have -
> Wall
> or -Wextra or something like that enabled?
I'm using ReSharper C++ which is using clang-tidy from clang 13.0
with -Weverything
What settings do you use?
> IMO a better fix for this would be to wrap the macro in a do {} while
> (0) to keep the macro calls function-like.
Isn't that a bit too... hm.. much/ugly?
> Anyway, you should have mentioned in the commit message that your aim
> is to fix this uncommon warning.
Yes, that makes sense.
> > I don't know how others are working, but I use to work in a way
> where
> > such warnings are shown in the editor and in lists in the IDE
> > even without compilation. Now - when you have a code file that
> > generates like 20, 50 or more warnings, it's much harder to spot
> > those warnings that might be really relevant and hinting at a
> mistake,
> > and you might be just too lazy to go through them each time.
> >
> > The clang diagnostics have been helpful in spotting some actual
> > issues in this very file. That's why I consider it worthwhile
> > to also eliminate such "non-issues".
> >
>
> I also work like that; e.g. my recent ac3.h header patchset was
> inspired
> by clangd not liking cycles in header inclusions ("In included file:
> main file cannot be included recursively when building a preamble").
Yea, I gathered from some of your patches that you must be using
some tooling as well. Would you allow me the question which IDE you
are using?
Thanks a lot,
softworkz
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-05-16 22:03 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-22 15:13 [PATCH 00/11] libavformat/asf: fix handling of byte array length values ffmpegagent
2021-12-22 15:13 ` [PATCH 01/11] " ffmpegagent
2021-12-22 15:13 ` [PATCH 02/11] libavformat/asfdec: fix get_value return type and add checks for ffmpegagent
2021-12-22 15:13 ` [PATCH 03/11] libavformat/asfdec: fix type of value_len ffmpegagent
2021-12-22 15:13 ` [PATCH 04/11] libavformat/asfdec: fixing get_tag ffmpegagent
2021-12-22 15:13 ` [PATCH 05/11] libavformat/asfdec: implement parsing of GUID values ffmpegagent
2021-12-22 15:13 ` [PATCH 06/11] libavformat/asfdec: remove unused parameters ffmpegagent
2021-12-22 18:16 ` Soft Works
2021-12-22 15:13 ` [PATCH 07/11] libavformat/asfdec: fix macro definition and use ffmpegagent
2021-12-22 16:23 ` Soft Works
2021-12-22 15:13 ` [PATCH 08/11] libavformat/asfdec: remove variable redefinition in inner scope ffmpegagent
2021-12-22 15:13 ` [PATCH 09/11] libavformat/asfdec: ensure variables are initialized ffmpegagent
2021-12-22 15:13 ` [PATCH 10/11] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() ffmpegagent
2021-12-22 15:13 ` [PATCH 11/11] libavformat/asfdec: fix variable types and add checks for unsupported values ffmpegagent
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 00/11] libavformat/asf: fix handling of byte array length values ffmpegagent
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 01/11] " softworkz
2022-05-07 18:48 ` Michael Niedermayer
2022-05-08 2:27 ` Soft Works
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 02/11] libavformat/asfdec: fix get_value return type and add checks for softworkz
2022-05-07 18:57 ` Michael Niedermayer
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 03/11] libavformat/asfdec: fix type of value_len softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 04/11] libavformat/asfdec: fixing get_tag softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 05/11] libavformat/asfdec: implement parsing of GUID values softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 06/11] libavformat/asfdec: remove unused parameters softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 07/11] libavformat/asfdec: fix macro definition and use softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 08/11] libavformat/asfdec: remove variable redefinition in inner scope softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 09/11] libavformat/asfdec: ensure variables are initialized softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 10/11] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() softworkz
2022-05-07 9:36 ` [FFmpeg-devel] [PATCH v2 11/11] libavformat/asfdec: fix variable types and add checks for unsupported values softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 00/11] libavformat/asf: fix handling of byte array length values ffmpegagent
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 01/11] " softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 02/11] libavformat/asfdec: fix get_value return type and add checks for softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 03/11] libavformat/asfdec: fix type of value_len softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 04/11] libavformat/asfdec: fixing get_tag softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 05/11] libavformat/asfdec: implement parsing of GUID values softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 06/11] libavformat/asfdec: remove unused parameters softworkz
2022-05-08 18:50 ` Michael Niedermayer
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 07/11] libavformat/asfdec: fix macro definition and use softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 08/11] libavformat/asfdec: remove variable redefinition in inner scope softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 09/11] libavformat/asfdec: ensure variables are initialized softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 10/11] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() softworkz
2022-05-08 3:01 ` [FFmpeg-devel] [PATCH v3 11/11] libavformat/asfdec: fix variable types and add checks for unsupported values softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 00/10] libavformat/asf: fix handling of byte array length values ffmpegagent
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 01/10] " softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 02/10] libavformat/asfdec: fix get_value return type and add checks for softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 03/10] libavformat/asfdec: fix type of value_len softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 04/10] libavformat/asfdec: fixing get_tag softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 05/10] libavformat/asfdec: implement parsing of GUID values softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 06/10] libavformat/asfdec: fix macro definition and use softworkz
2022-05-15 18:12 ` Andreas Rheinhardt
2022-05-15 22:51 ` Soft Works
2022-05-16 8:48 ` Andreas Rheinhardt
2022-05-16 22:03 ` Soft Works [this message]
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 07/10] libavformat/asfdec: remove variable redefinition in inner scope softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 08/10] libavformat/asfdec: ensure variables are initialized softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 09/10] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() softworkz
2022-05-14 20:55 ` [FFmpeg-devel] [PATCH v4 10/10] libavformat/asfdec: fix variable types and add checks for unsupported values softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 00/10] libavformat/asf: fix handling of byte array length values ffmpegagent
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 01/10] " softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 02/10] libavformat/asfdec: fix get_value return type and add checks for softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 03/10] libavformat/asfdec: fix type of value_len softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 04/10] libavformat/asfdec: fixing get_tag softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 05/10] libavformat/asfdec: implement parsing of GUID values softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 06/10] libavformat/asfdec: avoid clang warnings softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 07/10] libavformat/asfdec: remove variable redefinition in inner scope softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 08/10] libavformat/asfdec: ensure variables are initialized softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 09/10] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() softworkz
2022-05-21 5:21 ` [FFmpeg-devel] [PATCH v5 10/10] libavformat/asfdec: fix variable types and add checks for unsupported values softworkz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM8P223MB0365D7ECAD619B7CEE7FE390BACF9@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM \
--to=softworkz@hotmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git