j1939spy: main(): fix shift-count-overflow error

Fix the following error, by converting recvflags into a 64 bit type.

| /home/j1939spy.c: In function 'main':
| /home/j1939spy.c:248:36: error: left shift count >= width of type [-Werror=shift-count-overflow]
|   248 |                 if (recvflags & (1 << SCM_TIMESTAMP)) {
|       |                                    ^~
pull/542/head
Marc Kleine-Budde 2024-05-29 14:26:40 +02:00
parent e0bb44c908
commit 1405a90e8b
1 changed files with 6 additions and 6 deletions

View File

@ -99,7 +99,7 @@ int main(int argc, char **argv)
int filter = 0; int filter = 0;
uint8_t priority, dst_addr; uint8_t priority, dst_addr;
uint64_t dst_name; uint64_t dst_name;
long recvflags; uint64_t recvflags;
/* argument parsing */ /* argument parsing */
while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1) while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1)
@ -230,11 +230,11 @@ int main(int argc, char **argv)
case SOL_SOCKET: case SOL_SOCKET:
if (cmsg->cmsg_type == SCM_TIMESTAMP) { if (cmsg->cmsg_type == SCM_TIMESTAMP) {
memcpy(&tdut, CMSG_DATA(cmsg), sizeof(tdut)); memcpy(&tdut, CMSG_DATA(cmsg), sizeof(tdut));
recvflags |= 1 << cmsg->cmsg_type; recvflags |= 1ULL << cmsg->cmsg_type;
} }
break; break;
case SOL_CAN_J1939: case SOL_CAN_J1939:
recvflags |= 1 << cmsg->cmsg_type; recvflags |= 1ULL << cmsg->cmsg_type;
if (cmsg->cmsg_type == SCM_J1939_DEST_ADDR) if (cmsg->cmsg_type == SCM_J1939_DEST_ADDR)
dst_addr = *CMSG_DATA(cmsg); dst_addr = *CMSG_DATA(cmsg);
else if (cmsg->cmsg_type == SCM_J1939_DEST_NAME) else if (cmsg->cmsg_type == SCM_J1939_DEST_NAME)
@ -245,7 +245,7 @@ int main(int argc, char **argv)
} }
} }
if (recvflags & (1 << SCM_TIMESTAMP)) { if (recvflags & (1ULL << SCM_TIMESTAMP)) {
if ('z' == s.time) { if ('z' == s.time) {
if (!tref.tv_sec) if (!tref.tv_sec)
tref = tdut; tref = tdut;
@ -270,9 +270,9 @@ abs_time:
} }
} }
printf(" %s ", libj1939_addr2str(&src)); printf(" %s ", libj1939_addr2str(&src));
if (recvflags & (1 << SCM_J1939_DEST_NAME)) if (recvflags & (1ULL << SCM_J1939_DEST_NAME))
printf("%016llx ", (unsigned long long)dst_name); printf("%016llx ", (unsigned long long)dst_name);
else if (recvflags & (1 << SCM_J1939_DEST_ADDR)) else if (recvflags & (1ULL << SCM_J1939_DEST_ADDR))
printf("%02x ", dst_addr); printf("%02x ", dst_addr);
else else
printf("- "); printf("- ");