cangen: flush the len8_dlc element at each iteration

The variable 'frame' is declared on the stack and is reused at each
iteration of the while loop.

If not flushed, garbage data from the previous iteration of the loop
could remain causing unexpected behavior. This is the case in DLC
random mode: the field frame.len8_dlc is not cleared when the dlc is
exactly 8 and the len8_dlc value of the previous iteration will be
sent again.

This can be observed by running 'cangen -8 can0'. Once a frame of DLC
in the range 9..15 is generated, no more frames of DLC 8 show out in
the log.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/260/head
Vincent Mailhol 2020-11-01 16:42:27 +01:00 committed by Oliver Hartkopp
parent 45b9a4812a
commit 0b6af299d1
1 changed files with 2 additions and 0 deletions

View File

@ -172,6 +172,7 @@ int main(int argc, char **argv)
struct sockaddr_can addr;
static struct canfd_frame frame;
struct can_frame *ccf = (struct can_frame *)&frame;
int nbytes;
int i;
struct ifreq ifr;
@ -385,6 +386,7 @@ int main(int argc, char **argv)
while (running) {
frame.flags = 0;
ccf->len8_dlc = 0;
if (count && (--count == 0))
running = 0;