public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* xfstests, weird looking code in src/resvtest.c
@ 2014-06-17 16:20 scameron
  2014-06-17 23:06 ` Dave Chinner
  0 siblings, 1 reply; 2+ messages in thread
From: scameron @ 2014-06-17 16:20 UTC (permalink / raw)
  To: xfs; +Cc: scameron


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: xfstests, weird looking code in src/resvtest.c
  2014-06-17 16:20 xfstests, weird looking code in src/resvtest.c scameron
@ 2014-06-17 23:06 ` Dave Chinner
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Chinner @ 2014-06-17 23:06 UTC (permalink / raw)
  To: scameron; +Cc: xfs

On Tue, Jun 17, 2014 at 11:20:44AM -0500, scameron@beardog.cce.hp.com wrote:
> 
> 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.

There's a recent patch on the fstests list (fstests@vger.kernel.org)
that fixes this that I haven't picked up yet.

For actual test harness issues, you should use
fstests@vger.kernel.org now, not xfs@oss.sgi.com...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-17 23:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17 16:20 xfstests, weird looking code in src/resvtest.c scameron
2014-06-17 23:06 ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox