From: Alex Elder <elder@ieee.org>
To: Jeff Moyer <jmoyer@redhat.com>, fstests@vger.kernel.org
Subject: Re: [patch] resvtest.c: fix invalid use of sizeof()
Date: Thu, 05 Jun 2014 14:29:54 -0500 [thread overview]
Message-ID: <5390C532.2060706@ieee.org> (raw)
In-Reply-To: <x49lhtbw42a.fsf@segfault.boston.devel.redhat.com>
On 06/05/2014 02:26 PM, Jeff Moyer wrote:
> Hi,
>
> sizeof(pointer) will give you the size of a pointer, not the space
> allocated to it. I noticed this when gcc complained:
>
> resvtest.c:76:33: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
> memset(writebuffer, 'A', sizeof(writebuffer));
Nice catch, gcc!
Looks good.
Reviewed-by: Alex Elder <elder@linaro.org>
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
>
> diff --git a/src/resvtest.c b/src/resvtest.c
> index 037d9ea..ecad031 100644
> --- a/src/resvtest.c
> +++ b/src/resvtest.c
> @@ -73,7 +73,7 @@ main(int argc, char **argv)
> perror("open");
> exit(1);
> }
> - memset(writebuffer, 'A', sizeof(writebuffer));
> + memset(writebuffer, 'A', bsize);
>
> unlink(filename);
> writefd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
> @@ -111,7 +111,7 @@ main(int argc, char **argv)
> char *p;
> int numerrors;
>
> - if (write(writefd, writebuffer, sizeof(writebuffer)) < 0) {
> + if (write(writefd, writebuffer, bsize) < 0) {
> perror("write");
> exit(1);
> }
> @@ -128,11 +128,11 @@ main(int argc, char **argv)
> lseek(readfd, SEEK_SET, 0);
> numerrors = 0;
> for (j = 0; j < n; j++) {
> - if (read(readfd, readbuffer, sizeof(readbuffer)) < 0) {
> + if (read(readfd, readbuffer, bsize) < 0) {
> perror("read");
> exit(1);
> }
> - for (i = 0; i < sizeof(readbuffer); i++) {
> + for (i = 0; i < bsize; i++) {
> if (readbuffer[i] != 'A') {
> fprintf(stderr,
> "errors detected in file, pos: %d (%lld+%d), nwrites: %d [val=0x%x].\n",
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
prev parent reply other threads:[~2014-06-05 19:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-05 19:26 [patch] resvtest.c: fix invalid use of sizeof() Jeff Moyer
2014-06-05 19:29 ` Alex Elder [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=5390C532.2060706@ieee.org \
--to=elder@ieee.org \
--cc=fstests@vger.kernel.org \
--cc=jmoyer@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.