diff --git a/lib/path.c b/lib/path.c index 6922e2770..05b608e57 100644 --- a/lib/path.c +++ b/lib/path.c @@ -928,6 +928,7 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i FILE *f; size_t setsize, len = maxcpus * 7; char buf[len]; + int rc; *set = NULL; @@ -935,10 +936,12 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i if (!f) return -errno; - if (!fgets(buf, len, f)) - return -errno; + rc = fgets(buf, len, f) == NULL ? -errno : 0; fclose(f); + if (rc) + return rc; + len = strlen(buf); if (buf[len - 1] == '\n') buf[len - 1] = '\0';