public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: scameron@beardog.cce.hp.com
To: xfs@oss.sgi.com
Cc: scameron@beardog.cce.hp.com
Subject: xfstests, weird looking code in src/resvtest.c
Date: Tue, 17 Jun 2014 11:20:44 -0500	[thread overview]
Message-ID: <20140617162044.GL29459@beardog.cce.hp.com> (raw)


This code in xfstests src/resvtest.c looks pretty strange:

...
 32         char            *readbuffer, *writebuffer;
...
 70         readbuffer = memalign(psize, bsize);
 71         writebuffer = memalign(psize, bsize);
 72         if (!readbuffer || !writebuffer) {
 73                 perror("open");
 74                 exit(1);
 75         }
 76         memset(writebuffer, 'A', sizeof(writebuffer));

^^^ writebuffer is a pointer, so using sizeof(writebuffer) here is
odd. Is it intentional to put either 4 or 8 A's into writebuffer
depending on sizeof a pointer?  Seems unlikely.

110         while (++n < iterations) {
111                 char *p;
112                 int numerrors;
113 
114                 if (write(writefd, writebuffer, sizeof(writebuffer)) < 0) {
115                         perror("write");
116                         exit(1);
117                 }

So that write will write sizeof a pointer's worth of whatever's in writebuffer.
Intentional?  Again, seems unlikely.

This seems like maybe somebody initially declared writebuffer as an array, but
later went back and changed it to a pointer, but forgot to fixup everywhere that
referred to sizeof(writebuffer).

I would have sent a patch but I'm not sure what this code is trying to do.

gcc 4.4.7 (what comes with RHEL6u5) doesn't warn about this, but 4.8.3 does.

-- steve

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2014-06-17 16:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-17 16:20 scameron [this message]
2014-06-17 23:06 ` xfstests, weird looking code in src/resvtest.c Dave Chinner

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=20140617162044.GL29459@beardog.cce.hp.com \
    --to=scameron@beardog.cce.hp.com \
    --cc=xfs@oss.sgi.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