module/battery: convert asserts to real error checks

This commit is contained in:
Daniel Eklöf 2018-12-25 12:25:24 +01:00
parent d81547066d
commit 30332670aa

View file

@ -109,8 +109,10 @@ readline_from_fd(int fd)
ssize_t sz = read(fd, buf, sizeof(buf) - 1); ssize_t sz = read(fd, buf, sizeof(buf) - 1);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
if (sz < 0) if (sz < 0) {
LOG_WARN("failed to read from FD=%d", fd);
return NULL; return NULL;
}
buf[sz] = '\0'; buf[sz] = '\0';
for (ssize_t i = sz - 1; i >= 0 && buf[i] == '\n'; sz--) for (ssize_t i = sz - 1; i >= 0 && buf[i] == '\n'; sz--)
@ -123,7 +125,8 @@ static long
readint_from_fd(int fd) readint_from_fd(int fd)
{ {
const char *s = readline_from_fd(fd); const char *s = readline_from_fd(fd);
assert(s != NULL); if (s == NULL)
return 0;
long ret; long ret;
int r = sscanf(s, "%ld", &ret); int r = sscanf(s, "%ld", &ret);