min-protocol / min

The MIN protocol specification and reference implementation
257 stars 88 forks source link

Time variable not initialized in transport_fifo_reset #50

Open kinimodkoch opened 1 year ago

kinimodkoch commented 1 year ago

In min.c, the function transport_fifo_reset uses the now variable, but does not update it first. I suggest to insert a call to min_time_ms().

static void transport_fifo_reset(struct min_context *self)
{
    // Clear down the transmission FIFO queue
    self->transport_fifo.n_frames = 0;
    self->transport_fifo.head_idx = 0;
    self->transport_fifo.tail_idx = 0;
    self->transport_fifo.n_ring_buffer_bytes = 0;
    self->transport_fifo.ring_buffer_tail_offset = 0;
    self->transport_fifo.sn_max = 0;
    self->transport_fifo.sn_min = 0;
    self->transport_fifo.rn = 0;

    // Reset the timers
    now = min_time_ms();  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< I suggest to insert this line
    self->transport_fifo.last_received_anything_ms = now;
    self->transport_fifo.last_sent_ack_time_ms = now;
    self->transport_fifo.last_received_frame_ms = 0;
}
bojanpotocnik commented 10 months ago

Function transport_fifo_reset() is only called from:

min_poll() is intended to be called every "tick"/loop iteration, so I think it was meant as a feature to only update now inside this function. This ensures all operations in this processing step will use the same now time, including any later calls to min_transport_reset().