Skip to content

Commit

Permalink
[iioadaptor] Improve strtol error handling. Contributes to MER#2076
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVanAssche committed Jan 23, 2020
1 parent b49a908 commit 7074a07
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions adaptors/iioadaptor/iioadaptor.cpp
Expand Up @@ -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: {
Expand Down

0 comments on commit 7074a07

Please sign in to comment.