###Bug #1###
Bug #1
You only leave room for 4 timestamps here:
uint32_t timestamps[4];
But if your file happens to contain 5+ timestamps in a row that all fit inside the time window, then your code will happily write past the end of the timestamps
array. You need to check if you've reached 4 each time you add a new entry to the array.
When there are 5+ entries in a row that fit within the same window, I'm not sure if your program is supposed to output multiple quadruples or not, but you will need to figure out what you want to do in that case.
###Bug #2###
Bug #2
Your program currently can miss possible quadruples because it may skip past entries it should be looking at. For example, suppose the first six times were:
500, 599, 600, 601, 602, 900
with a time window of 100
. Your program would start with time 500
and look for three more entries that fit within the 500..600
window. It would accept 599
and 600
but then fail at 601
. But when it fails at 601
, it will start a new window starting at 601
instead of "shifting the window by one" to start at 599
. So it will end up missing the 599, 600, 601, 602
quadruple.
When you find an entry that falls outside the given window, you need to shift your window one by one until the newest entry falls inside the window. In other words, you throw out timestamps[0]
and shift all the other entries down, and then retry the newest entry to see if it fits in the new window.
This could best be done with a circular buffer, where you wouldn't actually have to shift any entries (you would just shift the starting point forward).
###Possible Bug #3###
Possible Bug #3
You mentioned that time could wrap around when it overflowed 4 bytes. But your code seems to reject any wrapped around times as not being valid:
if( curr_timestamp - timestamps[0] <= WINDOW_SIZE && curr_timestamp > timestamps[0] )
Perhaps that is what you intended, but if you wanted to find a quadruple that occurred near the wraparound time, you should allow wraparounds to be legal by removing the wraparound check like this:
if (curr_timestamp - timestamps[0] <= WINDOW_SIZE)