From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: fstests@vger.kernel.org, zlang@kernel.org
Subject: Re: [PATCH] fstests: fix compilation error in splice2pipe on old (<C99) compilers
Date: Tue, 16 May 2023 07:54:37 -0700 [thread overview]
Message-ID: <20230516145437.GA858795@frogsfrogsfrogs> (raw)
In-Reply-To: <20230516102301.571503-1-aalbersh@redhat.com>
On Tue, May 16, 2023 at 12:23:03PM +0200, Andrey Albershteyn wrote:
> Compilation fails on system with compiler which uses older C dialect
> (e.g. RHEL7; gcc with gnu90) with:
>
> splice2pipe.c: In function 'prepare_pipe':
> splice2pipe.c:54:2: error: 'for' loop initial declarations are only allowed in C99 mode
> for (unsigned r = pipe_size; r > 0;) {
>
> Fix it by declaring 'r' outside of the loop.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Not sure if you need to zero-init the variable, but eh looks good to me
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> src/splice2pipe.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/splice2pipe.c b/src/splice2pipe.c
> index bd33ff67..00b3a23a 100644
> --- a/src/splice2pipe.c
> +++ b/src/splice2pipe.c
> @@ -41,6 +41,7 @@
> */
> static void prepare_pipe(int p[2])
> {
> + unsigned int r = 0;
> if (pipe(p)) {
> perror("pipe failed");
> abort();
> @@ -51,7 +52,7 @@ static void prepare_pipe(int p[2])
>
> /* fill the pipe completely; each pipe_buffer will now have
> the PIPE_BUF_FLAG_CAN_MERGE flag */
> - for (unsigned r = pipe_size; r > 0;) {
> + for (r = pipe_size; r > 0;) {
> unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
> write(p[1], buffer, n);
> r -= n;
> @@ -59,7 +60,7 @@ static void prepare_pipe(int p[2])
>
> /* drain the pipe, freeing all pipe_buffer instances (but
> leaving the flags initialized) */
> - for (unsigned r = pipe_size; r > 0;) {
> + for (r = pipe_size; r > 0;) {
> unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
> read(p[0], buffer, n);
> r -= n;
> --
> 2.31.1
>
prev parent reply other threads:[~2023-05-16 14:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 10:23 [PATCH] fstests: fix compilation error in splice2pipe on old (<C99) compilers Andrey Albershteyn
2023-05-16 14:54 ` Darrick J. Wong [this message]
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=20230516145437.GA858795@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@redhat.com \
--cc=fstests@vger.kernel.org \
--cc=zlang@kernel.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox