From dec1efba06aeadcd9a4f13e8591f2efa016a24a0 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 1 Sep 2015 19:19:24 +1200 Subject: Replace asprintf calls with snprintf --- getgov.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'getgov.c') diff --git a/getgov.c b/getgov.c index e86f7fd..7ff8562 100644 --- a/getgov.c +++ b/getgov.c @@ -57,14 +57,11 @@ void gg_init() bool gg_current(int core, char* out, int size) { FILE* fd; - char *path; - asprintf(&path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", core); + char path[1024]; + snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", core); if (!(fd = fopen(path, "r"))) - { - free(path); return false; - } fgets(out, size, fd); @@ -73,7 +70,6 @@ bool gg_current(int core, char* out, int size) *newline = '\0'; fclose(fd); - free(path); return true; } @@ -83,18 +79,15 @@ bool gg_current(int core, char* out, int size) **********************************************************************/ bool gg_available(int core, char* out, int size) { - char *path; + char path[1024]; FILE *fd; - asprintf(&path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core); + snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core); if (!(fd = fopen(path, "r"))) - { - free(path); return false; - } + fgets(out, size, fd); fclose(fd); - free(path); return true; } -- cgit v1.1