If the command does not stop immediately after the last sample, there
can be more data to read than we have room for. Make sure the 'while'
loop 'read()' does not overrun the end of the malloc'ed 'buf'.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
go=1;
b=buf;
while(go){
- ret = read(comedi_fileno(device), b, N_SAMPLES * sample_size);
+ ret = read(comedi_fileno(device), b,
+ (N_SAMPLES * sample_size) - total);
if(ret<0){
if(errno==EAGAIN){
usleep(10000);
total += ret;
b += ret;
if(verbose) printf("read %d %d\n",ret,total);
+ if(total >= (N_SAMPLES * sample_size)){
+ go = 0;
+ }
}
}