Re: [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mauro and YongSu,

Answering my own question: The reason nobody has triggered this yet, is because the buffer size used is power of two. Because unsigned modulus is used, the result becomes correct. See below. But if non-power of two ring-buffer is used, then the result becomes incorrect. There is no block for non-power of two sized buffers. See:

https://github.com/search?q=dvb_set_pesfilter&type=code

cat << EOF > testX.c
#include <stdio.h>

int
main()
{
int consumed_old;
int consumed_fix;
size_t idx = 3;
ssize_t pread = 15;
ssize_t size = 256;

consumed_old = (idx - pread) % size;

consumed_fix = (idx - pread);
if (consumed_fix < 0)
consumed_fix += size;

printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size);

size = 254;

consumed_old = (idx - pread) % size;

consumed_fix = (idx - pread);
if (consumed_fix < 0)
consumed_fix += size;

printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size);

return (0);
}
EOF

cc testX.c && ./a.out
old=244 new=244 size=256
old=244 new=242 size=254

So either push the suggested fix, or block non-power of two buffer sizes!

Best regards,
--HPS



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux