Hi!
I've been seeing errors with our application, and have narrowed it down to cbufFindByte() returning false matches.
It happens when a new character arrives (from interrupt routine) while executing cbufFindByte().
(The routine falsely assumes that there's more data starting from the beginning of the buffer.)
The following fix works for me:
WORD cbufFindByte(CIRBUF* pBuf, WORD offset, BYTE value) {
- WORD i;
+ WORD i, n;
WORD sizeCtgs; //Size of block of contiguous data we can search
BYTE* pCtgs; //Pointer to block of contiguous data we can search
BOOL firstLoop = TRUE;
WORD rdArrSize=0;
+ n = cbufGetCount(pBuf); //This might change, so read it now - idb
//Get pointer and size of first continuous block of data
pCtgs = cbufGetRdArr(pBuf);
sizeCtgs = cbufGetRdArrSize(pBuf);
@@ -260,10 +261,10 @@
//Byte not found yet:
// - Check if there is a second contiguous block of data. If so, search it too
// - If no second contigous block, return "Not Found"
- if (firstLoop && (cbufGetCount(pBuf) > sizeCtgs)){
+ if (firstLoop && (n > sizeCtgs)){
firstLoop = FALSE;
rdArrSize = sizeCtgs; //Remember size of first contiguous block.
- sizeCtgs = cbufGetCount(pBuf) - sizeCtgs;
+ sizeCtgs = n - sizeCtgs;
pCtgs = pBuf->buf; //Second contiguous block is from beginning of buffer
}
Regards,
Ian