From: Cyril Hrubis <chrubis@suse.cz>
To: Sven Schnelle <svens@linux.ibm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3] mmap01: fix check_file() test for file corruption
Date: Thu, 23 Jan 2025 15:42:51 +0100 [thread overview]
Message-ID: <Z5JVa6MgafKoBiyt@yuki.lan> (raw)
In-Reply-To: <20250123143633.3680575-1-svens@linux.ibm.com>
Hi!
> diff --git a/testcases/kernel/syscalls/mmap/mmap01.c b/testcases/kernel/syscalls/mmap/mmap01.c
> index c93c37ceda52..ffbe6485a09c 100644
> --- a/testcases/kernel/syscalls/mmap/mmap01.c
> +++ b/testcases/kernel/syscalls/mmap/mmap01.c
> @@ -35,19 +35,23 @@ static void check_file(void)
> {
> int i, fildes, buf_len = sizeof(STRING) + 3;
> char buf[buf_len];
> + ssize_t len;
>
> fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
> - SAFE_READ(0, fildes, buf, sizeof(buf));
> -
> - for (i = 0; i < buf_len; i++)
> + len = SAFE_READ(0, fildes, buf, sizeof(buf));
> + if (len != strlen(STRING)) {
> + tst_res(TFAIL, "Read %zi expected %zu", len, strlen(STRING));
> + goto out;
> + }
> + for (i = 0; i < len; i++)
> if (buf[i] == 'X' || buf[i] == 'Y' || buf[i] == 'Z')
> break;
>
> - if (i == buf_len)
> + if (i == len)
> tst_res(TPASS, "Specified pattern not found in file");
> else
> tst_res(TFAIL, "Specified pattern found in file");
> -
> +out:
> SAFE_CLOSE(fildes);
We could close the file right after the read, that would have avoided
the goto, but I guess that the patch is good enough now.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-01-23 14:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 14:36 [LTP] [PATCH v3] mmap01: fix check_file() test for file corruption Sven Schnelle
2025-01-23 14:42 ` Cyril Hrubis [this message]
2025-01-23 18:12 ` Petr Vorel
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=Z5JVa6MgafKoBiyt@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=svens@linux.ibm.com \
/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