From: Jozef Pupava <jpupava@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] Avoid zero or negative int results in calculations
Date: Tue, 24 Mar 2020 14:38:39 +0100 [thread overview]
Message-ID: <20200324143839.3647c485@daedruan> (raw)
Define BUF_SIZE smaller than BLOCKSIZE for possitive offset result
Acked-by: Martin Doucha <mdoucha@suse.cz>
Signed-off-by: Jozef Pupava <jpupava@suse.com>
---
testcases/kernel/syscalls/fsync/fsync02.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/fsync/fsync02.c b/testcases/kernel/syscalls/fsync/fsync02.c
index 9506b4868..42a45d0c5 100644
--- a/testcases/kernel/syscalls/fsync/fsync02.c
+++ b/testcases/kernel/syscalls/fsync/fsync02.c
@@ -22,9 +22,10 @@
#define BLOCKSIZE 8192
#define MAXBLKS 262144
#define TIME_LIMIT 120
+#define BUF_SIZE 2048
char tempfile[40] = "";
-char pbuf[BUFSIZ];
+char pbuf[BUF_SIZE];
int fd;
off_t max_blks = MAXBLKS;
@@ -47,7 +48,7 @@ static void setup(void) {
#ifdef LARGEFILE
SAFE_FCNTL(fd, F_SETFL, O_LARGEFILE);
- SAFE_WRITE(1, fd, pbuf, BUFSIZ);
+ SAFE_WRITE(1, fd, pbuf, BUF_SIZE);
#endif
}
@@ -60,17 +61,15 @@ static void run(void) {
double time_delta;
long int random_number;
- while (max_block <= data_blocks) {
- random_number = rand();
- max_block = random_number % max_blks;
- data_blocks = random_number % 1000 + 1;
- }
+ random_number = rand();
+ max_block = random_number % max_blks + 1;
+ data_blocks = random_number % max_block;
for (i = 1; i <= data_blocks; i++) {
offset = i * ((BLOCKSIZE * max_block) / data_blocks);
- offset -= BUFSIZ;
+ offset -= BUF_SIZE;
SAFE_LSEEK(fd, offset, SEEK_SET);
- SAFE_WRITE(1, fd, pbuf, BUFSIZ);
+ SAFE_WRITE(1, fd, pbuf, BUF_SIZE);
}
time_start = time(0);
--
2.16.4
next reply other threads:[~2020-03-24 13:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 13:38 Jozef Pupava [this message]
2020-03-26 8:45 ` [LTP] [PATCH 2/2] Avoid zero or negative int results in calculations Petr Vorel
2020-03-26 13:46 ` Cyril Hrubis
2020-03-26 20:32 ` Petr Vorel
2020-03-27 9:57 ` Petr Vorel
2020-03-27 10:15 ` Jozef Pupava
2020-03-27 10:17 ` Martin Doucha
2020-03-27 15:23 ` 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=20200324143839.3647c485@daedruan \
--to=jpupava@suse.cz \
--cc=ltp@lists.linux.it \
/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