warn("Failed to get command output for %s", cmd);
return smprintf("%s", UNKNOWN_STR);
}
- fgets(buf, sizeof(buf), fp);
+ fgets(buf, sizeof(buf) - 1, fp);
pclose(fp);
- buf[sizeof(buf)] = '\0';
+ buf[sizeof(buf) - 1] = '\0';
if ((nlptr = strstr(buf, "\n")) != NULL) {
nlptr[0] = '\0';
return smprintf("%s", UNKNOWN_STR);
}
- if ((bytes_read = fread(buf, sizeof(char), sizeof(buf), fp)) == 0) {
+ if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
warn("swap_free: read error");
fclose(fp);
return smprintf("%s", UNKNOWN_STR);
return smprintf("%s", UNKNOWN_STR);
}
- if ((bytes_read = fread(buf, sizeof(char), sizeof(buf), fp)) == 0) {
+ if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
warn("swap_perc: read error");
fclose(fp);
return smprintf("%s", UNKNOWN_STR);
warn("Failed to open file /proc/meminfo");
return smprintf("%s", UNKNOWN_STR);
}
- if ((bytes_read = fread(buf, sizeof(char), sizeof(buf), fp)) == 0) {
+ if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
warn("swap_total: read error");
fclose(fp);
return smprintf("%s", UNKNOWN_STR);
warn("Failed to open file /proc/meminfo");
return smprintf("%s", UNKNOWN_STR);
}
- if ((bytes_read = fread(buf, sizeof(char), sizeof(buf), fp)) == 0) {
+ if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
warn("swap_used: read error");
fclose(fp);
return smprintf("%s", UNKNOWN_STR);