- From: David Schleef <ds_at_schleef.org>
- Date: Wed, 24 Jul 2002 17:23:41 -0700
On Wed, Jul 24, 2002 at 04:39:42PM -0700, Dan Christian wrote:
> Never mind. I forgot that comedi_buf_put_array is obsolete.
It's not obsolete, it's just not recommended (by me).
> This is what I did instead.
>
> n = comedi_buf_write_alloc (s->async, ii * sizeof (s16));
> comedi_buf_memcpy_to (s->async, 0, dp, n);
> comedi_buf_write_free (s->async, n);
> dp += n / sizeof (s16);
> ii -= n / sizeof (s16);
>
> if (ii > 0) { /* buffer wrap, 2 chunks */
> n = comedi_buf_write_alloc (s->async, ii * sizeof (s16));
> comedi_buf_memcpy_to (s->async, 0, dp, n);
> comedi_buf_write_free (s->async, n);
> } /* any residual is an error */
There's a problem: comedi_buf_write_alloc() will give you
allocations that wrap around the end of a buffer. At one point,
it did do this, so you might need to update CVS.
Instead, comedi_buf_memcpy_to() correctly handles wraparounds when
copying to a buffer. So you want something like:
n = comedi_buf_write_alloc (s->async, ii * sizeof (s16));
if(n<ii * sizeof (s16)){
/* this is a buffer overflow error condition */
/* big flames should erupt */
}
comedi_buf_memcpy_to (s->async, 0, dp, n);
comedi_buf_write_free (s->async, n);
dave...
Received on 2002-07-24Z23:23:41