can-utils: remove strict-aliasing compiler warning

GitHub user 'crossband' raised an issue regarding the strict-aliasing compiler
warning in his specific setup: https://github.com/linux-can/can-utils/issues/42

In fact memcpy() and memset() are a better solution than the former pointer
magics, so remove the issues and the compiler warning flag too.

Reported-by: crossband (https://github.com/crossband)
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2017-07-01 19:01:01 +02:00
parent 5109ca4f3c
commit 4c8fb05cb4
5 changed files with 24 additions and 21 deletions
+5 -3
View File
@@ -150,6 +150,7 @@ int main(int argc, char **argv)
int mtu, maxdlen;
uint64_t incdata = 0;
int incdlc = 0;
unsigned long rnd;
unsigned char fixdata[CANFD_MAX_DLEN];
int opt;
@@ -400,9 +401,10 @@ int main(int argc, char **argv)
if (data_mode == MODE_RANDOM) {
/* that's what the 64 bit alignment of data[] is for ... :) */
*(unsigned long*)(&frame.data[0]) = random();
*(unsigned long*)(&frame.data[4]) = random();
rnd = random();
memcpy(&frame.data[0], &rnd, 4);
rnd = random();
memcpy(&frame.data[4], &rnd, 4);
/* omit extra random number generation for CAN FD */
if (canfd && frame.len > 8) {