From 7074a07e7d5c2aab319a0226eaf6fb2a874af044 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Thu, 23 Jan 2020 19:38:19 +0100 Subject: [PATCH] [iioadaptor] Improve strtol error handling. Contributes to MER#2076 --- adaptors/iioadaptor/iioadaptor.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adaptors/iioadaptor/iioadaptor.cpp b/adaptors/iioadaptor/iioadaptor.cpp index 23b8593c..e2b25eff 100644 --- a/adaptors/iioadaptor/iioadaptor.cpp +++ b/adaptors/iioadaptor/iioadaptor.cpp @@ -434,10 +434,15 @@ void IioAdaptor::processSample(int fileId, int fd) sensordLogW() << "read():" << strerror(errno); return; } - result = strtol(buf, NULL, 10); - if (result == 0) + errno = 0; // reset errno before call + result = strtol(buf, NULL, 10); + + // If any conversion error occurs, abort + if (errno != 0) { + sensordLogW() << "strtol(): Unable to convert string to long"; return; + } switch(channel) { case 0: {