Use snprintf() instead of sprintf().
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Feb 2014 17:21:02 +0000 (19:21 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Feb 2014 17:26:07 +0000 (19:26 +0200)
src/plugins/cpufreq/cpufreq.c
src/plugins/thermal/thermal.c

index f9d2b9a..4057f65 100644 (file)
@@ -67,7 +67,7 @@ get_cur_governor(cpufreq *cf){
     FILE *fp;
     char buf[ 100 ], sstmp [ 256 ];
 
-    sprintf(sstmp,"%s/%s", (char*)cf->cpus->data, SCALING_GOV);
+    snprintf(sstmp, sizeof(sstmp), "%s/%s", (char*)cf->cpus->data, SCALING_GOV);
     if ((fp = fopen( sstmp, "r")) != NULL) {
         fgets(buf, 100, fp);
         buf[strlen(buf)-1] = '\0';
@@ -86,7 +86,7 @@ get_cur_freq(cpufreq *cf){
     FILE *fp;
     char buf[ 100 ], sstmp [ 256 ];
 
-    sprintf(sstmp,"%s/%s", (char*)cf->cpus->data, SCALING_CUR_FREQ);
+    snprintf(sstmp, sizeof(sstmp), "%s/%s", (char*)cf->cpus->data, SCALING_CUR_FREQ);
     if ((fp = fopen( sstmp, "r")) != NULL) {
         fgets(buf, 100, fp);
         buf[strlen(buf)-1] = '\0';
@@ -207,7 +207,7 @@ get_cpus(cpufreq *cf)
         /* Look for directories of the form "cpu<n>", where "<n>" is a decimal integer. */
         if ((strncmp(cpu, "cpu", 3) == 0) && (cpu[3] >= '0') && (cpu[3] <= '9'))
         {
-            sprintf(cpu_path, "%s/%s/cpufreq", SYSFS_CPU_DIRECTORY, cpu);
+            snprintf(cpu_path, sizeof(cpu_path), "%s/%s/cpufreq", SYSFS_CPU_DIRECTORY, cpu);
 
             GDir * cpufreqDir = g_dir_open(SYSFS_CPU_DIRECTORY, 0, NULL);
                if (cpufreqDir == NULL)
index f6db4fb..191d8f2 100644 (file)
@@ -79,7 +79,7 @@ proc_get_critical(char const* sensor_path){
 
     if(sensor_path == NULL) return -1;
 
-    sprintf(sstmp,"%s%s",sensor_path,PROC_THERMAL_TRIP);
+    snprintf(sstmp,sizeof(sstmp),"%s%s",sensor_path,PROC_THERMAL_TRIP);
 
     if (!(state = fopen( sstmp, "r"))) {
         ERR("thermal: cannot open %s\n", sstmp);
@@ -111,7 +111,7 @@ proc_get_temperature(char const* sensor_path){
 
     if(sensor_path == NULL) return -1;
 
-    sprintf(sstmp,"%s%s",sensor_path,PROC_THERMAL_TEMPF);
+    snprintf(sstmp,sizeof(sstmp),"%s%s",sensor_path,PROC_THERMAL_TEMPF);
 
     if (!(state = fopen( sstmp, "r"))) {
         ERR("thermal: cannot open %s\n", sstmp);
@@ -143,7 +143,7 @@ sysfs_get_critical(char const* sensor_path){
 
     if(sensor_path == NULL) return -1;
 
-    sprintf(sstmp,"%s%s",sensor_path,SYSFS_THERMAL_TRIP);
+    snprintf(sstmp,sizeof(sstmp),"%s%s",sensor_path,SYSFS_THERMAL_TRIP);
 
     if (!(state = fopen( sstmp, "r"))) {
         ERR("thermal: cannot open %s\n", sstmp);
@@ -170,7 +170,7 @@ sysfs_get_temperature(char const* sensor_path){
 
     if(sensor_path == NULL) return -1;
 
-    sprintf(sstmp,"%s%s",sensor_path,SYSFS_THERMAL_TEMPF);
+    snprintf(sstmp,sizeof(sstmp),"%s%s",sensor_path,SYSFS_THERMAL_TEMPF);
 
     if (!(state = fopen( sstmp, "r"))) {
         ERR("thermal: cannot open %s\n", sstmp);
@@ -270,7 +270,8 @@ update_display(thermal *th)
         panel_draw_label_text(th->plugin->panel, th->namew, "NA", TRUE, 1, TRUE);
     else
     {
-        sprintf(buffer, "<span color=\"#%06x\"><b>%02d</b></span>", gcolor2rgb24(&color), temp);
+        snprintf(buffer, sizeof(buffer), "<span color=\"#%06x\"><b>%02d</b></span>",
+                 gcolor2rgb24(&color), temp);
         gtk_label_set_markup (GTK_LABEL(th->namew), buffer) ;
     }
 
@@ -328,7 +329,7 @@ find_sensors(thermal* th, char const* directory, char const* subdir_prefix)
             if (strncmp(sensor_name, subdir_prefix, strlen(subdir_prefix)) != 0)
                 continue;
         }
-        sprintf(sensor_path,"%s%s/", directory, sensor_name);
+        snprintf(sensor_path,sizeof(sensor_path),"%s%s/", directory, sensor_name);
         add_sensor(th, sensor_path);
     }
     g_dir_close(sensorsDirectory);