[PATCH] cangen: flush the CAN frame at each iteration

From: Vincent Mailhol
Date: Sun Nov 01 2020 - 09:57:48 EST


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: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx>
---
cangen.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cangen.c b/cangen.c
index ab8122c..d7392b6 100644
--- a/cangen.c
+++ b/cangen.c
@@ -384,7 +384,7 @@ int main(int argc, char **argv)
}

while (running) {
- frame.flags = 0;
+ memset(&frame, 0, sizeof(frame));

if (count && (--count == 0))
running = 0;
--
2.26.2