summaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-12-07 17:17:43 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-14 08:59:54 +0000
commit97a08a7e37835f0e8619d22c83243bee26a2bff2 (patch)
tree66a44a6c977c9fe16311ec031204cb82aa84e6ca /low-can-binding/utils
parente190b7b3069d86fce25831c366bb0cd3fa615289 (diff)
Smalls improvements
- Improve robustness reading a BCM socket Adding checks on system calls and remove the initialization of the struct that will hold the received message, not so much needed in that case. - More accurate log message at subscription/unsubscription step whether this is a FD CAN messages or not and if this a subscription or an unsubscription that is requested. - Initialize the full struct of vehicle message to avoid memory warning about conditionnal jump based on uninitialized bytes. - Memleak: Free raw pointer on active diagnostic requests Change-Id: I4bbf4d851c0fa1efdb6fa6034fac3d1dcafa1a73 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/utils')
-rw-r--r--low-can-binding/utils/openxc-utils.cpp5
-rw-r--r--low-can-binding/utils/socketcan-bcm.cpp12
2 files changed, 14 insertions, 3 deletions
diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp
index e454121b..c06beabb 100644
--- a/low-can-binding/utils/openxc-utils.cpp
+++ b/low-can-binding/utils/openxc-utils.cpp
@@ -34,6 +34,7 @@
const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value)
{
openxc_VehicleMessage message;
+ ::memset(&message, 0, sizeof(message));
application_t& app = application_t::instance();
message.has_type = true;
@@ -98,6 +99,7 @@ const openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* re
const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message, uint64_t timestamp)
{
openxc_VehicleMessage v;
+ ::memset(&v, 0, sizeof(v));
v.has_type = true,
v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
@@ -120,6 +122,7 @@ const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& mes
const openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message)
{
openxc_VehicleMessage v;
+ ::memset(&v, 0, sizeof(v));
v.has_type = true,
v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
@@ -141,7 +144,7 @@ openxc_VehicleMessage build_VehicleMessage()
{
openxc_VehicleMessage v;
- ::memset(&v, 0, sizeof(openxc_VehicleMessage));
+ ::memset(&v, 0, sizeof(v));
return v;
}
diff --git a/low-can-binding/utils/socketcan-bcm.cpp b/low-can-binding/utils/socketcan-bcm.cpp
index d1fd8e0a..3f3a0968 100644
--- a/low-can-binding/utils/socketcan-bcm.cpp
+++ b/low-can-binding/utils/socketcan-bcm.cpp
@@ -74,14 +74,22 @@ namespace utils
{
struct utils::bcm_msg msg;
- ::memset(&msg, 0, sizeof(msg));
const struct sockaddr_can& addr = s.get_tx_address();
socklen_t addrlen = sizeof(addr);
struct ifreq ifr;
ssize_t nbytes = ::recvfrom(s.socket(), &msg, sizeof(msg), 0, (struct sockaddr*)&addr, &addrlen);
+ if(nbytes < 0)
+ {
+ AFB_ERROR("Can't read the next message from socket '%d'. '%s'", s.socket(), strerror(errno));
+ return s;
+ }
ifr.ifr_ifindex = addr.can_ifindex;
- ioctl(s.socket(), SIOCGIFNAME, &ifr);
+ if(ioctl(s.socket(), SIOCGIFNAME, &ifr) < 0)
+ {
+ AFB_ERROR("Can't read the interface name. '%s'", strerror(errno));
+ return s;
+ }
long unsigned int frame_size = nbytes-sizeof(struct bcm_msg_head);
AFB_DEBUG("Data available: %li bytes read. BCM head, opcode: %i, can_id: %i, nframes: %i", frame_size, msg.msg_head.opcode, msg.msg_head.can_id, msg.msg_head.nframes);