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>pull/48/head
parent
5109ca4f3c
commit
4c8fb05cb4
3
Makefile
3
Makefile
|
|
@ -43,8 +43,7 @@ PREFIX ?= /usr/local
|
||||||
|
|
||||||
MAKEFLAGS = -k
|
MAKEFLAGS = -k
|
||||||
|
|
||||||
CFLAGS = -O2 -Wall -Wno-parentheses \
|
CFLAGS = -O2 -Wall -Wno-parentheses
|
||||||
-fno-strict-aliasing
|
|
||||||
|
|
||||||
CPPFLAGS += -Iinclude \
|
CPPFLAGS += -Iinclude \
|
||||||
-D_FILE_OFFSET_BITS=64 \
|
-D_FILE_OFFSET_BITS=64 \
|
||||||
|
|
|
||||||
|
|
@ -689,9 +689,9 @@ int main(int argc, char **argv)
|
||||||
cmsg && (cmsg->cmsg_level == SOL_SOCKET);
|
cmsg && (cmsg->cmsg_level == SOL_SOCKET);
|
||||||
cmsg = CMSG_NXTHDR(&msg,cmsg)) {
|
cmsg = CMSG_NXTHDR(&msg,cmsg)) {
|
||||||
if (cmsg->cmsg_type == SO_TIMESTAMP)
|
if (cmsg->cmsg_type == SO_TIMESTAMP)
|
||||||
tv = *(struct timeval *)CMSG_DATA(cmsg);
|
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||||
else if (cmsg->cmsg_type == SO_RXQ_OVFL)
|
else if (cmsg->cmsg_type == SO_RXQ_OVFL)
|
||||||
dropcnt[i] = *(__u32 *)CMSG_DATA(cmsg);
|
memcpy(&dropcnt[i], CMSG_DATA(cmsg), sizeof(__u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for (unlikely) dropped frames on this specific socket */
|
/* check for (unlikely) dropped frames on this specific socket */
|
||||||
|
|
|
||||||
8
cangen.c
8
cangen.c
|
|
@ -150,6 +150,7 @@ int main(int argc, char **argv)
|
||||||
int mtu, maxdlen;
|
int mtu, maxdlen;
|
||||||
uint64_t incdata = 0;
|
uint64_t incdata = 0;
|
||||||
int incdlc = 0;
|
int incdlc = 0;
|
||||||
|
unsigned long rnd;
|
||||||
unsigned char fixdata[CANFD_MAX_DLEN];
|
unsigned char fixdata[CANFD_MAX_DLEN];
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
|
|
@ -400,9 +401,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (data_mode == MODE_RANDOM) {
|
if (data_mode == MODE_RANDOM) {
|
||||||
|
|
||||||
/* that's what the 64 bit alignment of data[] is for ... :) */
|
rnd = random();
|
||||||
*(unsigned long*)(&frame.data[0]) = random();
|
memcpy(&frame.data[0], &rnd, 4);
|
||||||
*(unsigned long*)(&frame.data[4]) = random();
|
rnd = random();
|
||||||
|
memcpy(&frame.data[4], &rnd, 4);
|
||||||
|
|
||||||
/* omit extra random number generation for CAN FD */
|
/* omit extra random number generation for CAN FD */
|
||||||
if (canfd && frame.len > 8) {
|
if (canfd && frame.len > 8) {
|
||||||
|
|
|
||||||
28
cansniffer.c
28
cansniffer.c
|
|
@ -64,8 +64,6 @@
|
||||||
|
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
#define U64_DATA(p) (*(unsigned long long*)(p)->data)
|
|
||||||
|
|
||||||
#define SETFNAME "sniffset."
|
#define SETFNAME "sniffset."
|
||||||
#define ANYDEV "any"
|
#define ANYDEV "any"
|
||||||
|
|
||||||
|
|
@ -370,7 +368,9 @@ void rx_setup (int fd, int id){
|
||||||
txmsg.msg_head.ival2.tv_sec = 0;
|
txmsg.msg_head.ival2.tv_sec = 0;
|
||||||
txmsg.msg_head.ival2.tv_usec = 0;
|
txmsg.msg_head.ival2.tv_usec = 0;
|
||||||
txmsg.msg_head.nframes = 1;
|
txmsg.msg_head.nframes = 1;
|
||||||
U64_DATA(&txmsg.frame) = (__u64) 0xFFFFFFFFFFFFFFFFULL;
|
|
||||||
|
/* set all bits to be relevant */
|
||||||
|
memset(&txmsg.frame.data, 0xFF, 8);
|
||||||
|
|
||||||
if (filter_id_only)
|
if (filter_id_only)
|
||||||
txmsg.msg_head.flags |= RX_FILTER_ID;
|
txmsg.msg_head.flags |= RX_FILTER_ID;
|
||||||
|
|
@ -478,7 +478,7 @@ int handle_keyb(int fd){
|
||||||
|
|
||||||
case '*' :
|
case '*' :
|
||||||
for (i=0; i < 2048; i++)
|
for (i=0; i < 2048; i++)
|
||||||
U64_DATA(&sniftab[i].notch) = (__u64) 0;
|
memset(&sniftab[i].notch.data, 0, 8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -492,7 +492,7 @@ int handle_keyb(int fd){
|
||||||
|
|
||||||
int handle_bcm(int fd, long currcms){
|
int handle_bcm(int fd, long currcms){
|
||||||
|
|
||||||
int nbytes, id;
|
int nbytes, id, i;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct bcm_msg_head msg_head;
|
struct bcm_msg_head msg_head;
|
||||||
|
|
@ -518,8 +518,9 @@ int handle_bcm(int fd, long currcms){
|
||||||
}
|
}
|
||||||
|
|
||||||
sniftab[id].current = bmsg.frame;
|
sniftab[id].current = bmsg.frame;
|
||||||
U64_DATA(&sniftab[id].marker) |=
|
for (i=0; i < 8; i++)
|
||||||
U64_DATA(&sniftab[id].current) ^ U64_DATA(&sniftab[id].last);
|
sniftab[id].marker.data[i] |= sniftab[id].current.data[i] ^ sniftab[id].last.data[i];
|
||||||
|
|
||||||
sniftab[id].timeout = (timeout)?(currcms + timeout):0;
|
sniftab[id].timeout = (timeout)?(currcms + timeout):0;
|
||||||
|
|
||||||
if (is_clr(id, DISPLAY))
|
if (is_clr(id, DISPLAY))
|
||||||
|
|
@ -533,7 +534,7 @@ int handle_bcm(int fd, long currcms){
|
||||||
|
|
||||||
int handle_timeo(int fd, long currcms){
|
int handle_timeo(int fd, long currcms){
|
||||||
|
|
||||||
int i;
|
int i, j;
|
||||||
int force_redraw = 0;
|
int force_redraw = 0;
|
||||||
static unsigned int frame_count;
|
static unsigned int frame_count;
|
||||||
|
|
||||||
|
|
@ -547,8 +548,10 @@ int handle_timeo(int fd, long currcms){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notch) {
|
if (notch) {
|
||||||
for (i=0; i < 2048; i++)
|
for (i=0; i < 2048; i++) {
|
||||||
U64_DATA(&sniftab[i].notch) |= U64_DATA(&sniftab[i].marker);
|
for (j=0; j < 8; j++)
|
||||||
|
sniftab[i].notch.data[j] |= sniftab[i].marker.data[j];
|
||||||
|
}
|
||||||
notch = 0;
|
notch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -569,7 +572,7 @@ int handle_timeo(int fd, long currcms){
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ((sniftab[i].hold) && (sniftab[i].hold < currcms)) {
|
if ((sniftab[i].hold) && (sniftab[i].hold < currcms)) {
|
||||||
U64_DATA(&sniftab[i].marker) = (__u64) 0;
|
memset(&sniftab[i].marker.data, 0, 8);
|
||||||
print_snifline(i);
|
print_snifline(i);
|
||||||
sniftab[i].hold = 0; /* disable update by hold */
|
sniftab[i].hold = 0; /* disable update by hold */
|
||||||
}
|
}
|
||||||
|
|
@ -670,8 +673,7 @@ void print_snifline(int id){
|
||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
U64_DATA(&sniftab[id].marker) = (__u64) 0;
|
memset(&sniftab[id].marker.data, 0, 8);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ rx_restart:
|
||||||
else
|
else
|
||||||
ptr = 9; /* dlc position Tiiiiiiiid */
|
ptr = 9; /* dlc position Tiiiiiiiid */
|
||||||
|
|
||||||
*(unsigned long long *) (&frame.data) = 0ULL; /* clear data[] */
|
memset(&frame.data, 0, 8); /* clear data[] */
|
||||||
|
|
||||||
if ((cmd | 0x20) == 'r' && buf[ptr] != '0') {
|
if ((cmd | 0x20) == 'r' && buf[ptr] != '0') {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue