diff --git a/src/app-manager.c b/src/app-manager.c index a3609f4..4118e9c 100644 --- a/src/app-manager.c +++ b/src/app-manager.c @@ -111,7 +111,7 @@ apps_add_application (GArray *apps, WnckApplication *application) app.application = application; app.pid = pid; - g_snprintf (app.name, 1024, "%s", wnck_application_get_name (application)); + g_snprintf (app.name, sizeof(app.name), "%s", wnck_application_get_name (application)); app.icon = wnck_application_get_mini_icon (application); g_object_ref (app.icon); diff --git a/src/main.c b/src/main.c index 1244bd6..0ddcdae 100644 --- a/src/main.c +++ b/src/main.c @@ -100,18 +100,18 @@ init_timeout (void) if (show_memory_in_xbytes) { used = g_format_size_full(memory_used, G_FORMAT_SIZE_IEC_UNITS); total = g_format_size_full(memory_total, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (memory_info, 64,"%s / %s", used, total); + g_snprintf (memory_info, sizeof(memory_info), "%s / %s", used, total); g_free(used); g_free(total); used = g_format_size_full(swap_used, G_FORMAT_SIZE_IEC_UNITS); total = g_format_size_full(swap_total, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (swap_info, 64,"%s / %s", used, total); + g_snprintf (swap_info, sizeof(swap_info), "%s / %s", used, total); g_free(used); g_free(total); } else { - g_snprintf (memory_info, 64, "%.0f%%", memory_percent); - g_snprintf (swap_info, 64, "%.0f%%", swap_percent); + g_snprintf (memory_info, sizeof(memory_info), "%.0f%%", memory_percent); + g_snprintf (swap_info, sizeof(swap_info), "%.0f%%", swap_percent); } xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info); @@ -122,7 +122,7 @@ init_timeout (void) if (gtk_status_icon_get_visible (status_icon)) { #if GTK_CHECK_VERSION (2,16,0) - g_snprintf (tooltip, 1024, + g_snprintf (tooltip, sizeof(tooltip), _("Processes: %u\n" "CPU: %.0f%%\n" "Memory: %s\n" @@ -130,7 +130,7 @@ init_timeout (void) num_processes, cpu, memory_info, swap_info); gtk_status_icon_set_tooltip_markup (GTK_STATUS_ICON (status_icon), tooltip); #else - g_snprintf (tooltip, 1024, + g_snprintf (tooltip, sizeof(tooltip), _("Processes: %u\n" "CPU: %.0f%%\n" "Memory: %s\n" diff --git a/src/process-statusbar.c b/src/process-statusbar.c index 56e01e5..e1f069e 100644 --- a/src/process-statusbar.c +++ b/src/process-statusbar.c @@ -158,7 +158,7 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV break; case PROP_MEMORY: - g_strlcpy(statusbar->memory, g_value_get_string (value), 64); + g_strlcpy(statusbar->memory, g_value_get_string (value), sizeof(statusbar->memory)); text = g_strdup_printf (_("Memory: %s"), statusbar->memory); gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text); #if GTK_CHECK_VERSION(3, 0, 0) @@ -172,7 +172,7 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV break; case PROP_SWAP: - g_strlcpy(statusbar->swap, g_value_get_string (value), 64); + g_strlcpy(statusbar->swap, g_value_get_string (value), sizeof(statusbar->swap)); text = g_strdup_printf (_("Swap: %s"), statusbar->swap); gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text); g_free (text); diff --git a/src/process-tree-view.c b/src/process-tree-view.c index 748610a..bc84dd3 100644 --- a/src/process-tree-view.c +++ b/src/process-tree-view.c @@ -345,7 +345,7 @@ save_columns_positions (XtmProcessTreeView *treeview) gchar columns_positions[COLUMNS_POSITIONS_STRLEN] = { 0 }; for (i = 0; i < N_COLUMNS; i++) - offset += g_snprintf (&columns_positions[offset], COLUMNS_POSITIONS_STRLEN - offset, "%d;", treeview->columns_positions[i]); + offset += g_snprintf (&columns_positions[offset], (sizeof(columns_positions) - offset), "%d;", treeview->columns_positions[i]); g_object_set (treeview->settings, "columns-positions", columns_positions, NULL); } diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c index 24c0122..4fbe8d1 100644 --- a/src/task-manager-freebsd.c +++ b/src/task-manager-freebsd.c @@ -145,7 +145,7 @@ get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task) } else { - g_strlcpy (task->cmdline, kp->ki_comm, 1024); + g_strlcpy (task->cmdline, kp->ki_comm, sizeof(task->cmdline)); } i = 0; diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c index 1262d08..488dbdf 100644 --- a/src/task-manager-linux.c +++ b/src/task-manager-linux.c @@ -40,7 +40,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_c *swap_total = 0; *swap_free = 0; - while (found < 6 && fgets (buffer, 1024, file) != NULL) + while (found < 6 && fgets (buffer, sizeof(buffer), file) != NULL) { found += sscanf (buffer, "MemTotal:\t%llu kB", (unsigned long long*)memory_total); found += sscanf (buffer, "MemFree:\t%llu kB", (unsigned long long*)memory_free); @@ -71,14 +71,14 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) static gulong jiffies_user_old = 0, jiffies_system_old = 0, jiffies_total_old = 0; gulong user = 0, user_nice = 0, system = 0, idle = 0; - if ((file = fopen (filename, "r")) == NULL || fgets (buffer, 1024, file) == NULL) + if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL) return FALSE; sscanf (buffer, "cpu\t%lu %lu %lu %lu", &user, &user_nice, &system, &idle); if (_cpu_count == 0) { - while (fgets (buffer, 1024, file) != NULL) + while (fgets (buffer, sizeof(buffer), file) != NULL) { if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u') break; @@ -130,7 +130,7 @@ get_task_cmdline (Task *task) gint i; gint c; - snprintf (filename, 96, "/proc/%i/cmdline", task->pid); + snprintf (filename, sizeof(filename), "/proc/%i/cmdline", task->pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -195,7 +195,7 @@ get_task_details (guint pid, Task *task) gchar buffer[1024]; snprintf (filename, sizeof(filename), "/proc/%d/stat", pid); - if ((file = fopen (filename, "r")) == NULL || fgets (buffer, 1024, file) == NULL) + if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL) return FALSE; fclose (file); @@ -342,11 +342,11 @@ pid_is_sleeping (guint pid) gchar buffer[1024]; gchar state[2]; - snprintf (filename, 96, "/proc/%i/status", pid); + snprintf (filename, sizeof(filename), "/proc/%i/status", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; - while (fgets (buffer, 1024, file) != NULL) + while (fgets (buffer, sizeof(buffer), file) != NULL) { if (sscanf (buffer, "State:\t%1s", state) > 0) break; diff --git a/src/task-manager-solaris.c b/src/task-manager-solaris.c index f2d54af..0afd6e0 100644 --- a/src/task-manager-solaris.c +++ b/src/task-manager-solaris.c @@ -176,7 +176,7 @@ get_task_details (guint pid, Task *task) struct passwd *pw; psinfo_t process; - snprintf (filename, 96, "/proc/%d/psinfo", pid); + snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -188,9 +188,9 @@ get_task_details (guint pid, Task *task) task->pid = (guint)process.pr_pid; task->ppid = (guint)process.pr_ppid; - g_strlcpy (task->name, process.pr_fname, 256); - snprintf (task->cmdline, 1024, "%s", process.pr_psargs); - snprintf (task->state, 16, "%c", process.pr_lwp.pr_sname); + g_strlcpy (task->name, process.pr_fname, sizeof(task->name)); + snprintf (task->cmdline, sizeof(task->cmdline), "%s", process.pr_psargs); + snprintf (task->state, sizeof(task->state), "%c", process.pr_lwp.pr_sname); task->vsz = (guint64)process.pr_size * 1024; task->rss = (guint64)process.pr_rssize * 1024; task->prio = (gushort)process.pr_lwp.pr_pri; @@ -237,7 +237,7 @@ pid_is_sleeping (guint pid) gchar state[2]; psinfo_t process; - snprintf (filename, 96, "/proc/%d/psinfo", pid); + snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -247,7 +247,7 @@ pid_is_sleeping (guint pid) return FALSE; } - snprintf (state, 2, "%c", process.pr_lwp.pr_sname); + snprintf (state, sizeof(state), "%c", process.pr_lwp.pr_sname); fclose (file); return (state[0] == 'T') ? TRUE : FALSE; diff --git a/src/task-manager.c b/src/task-manager.c index b63dfc9..76f0afe 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -237,8 +237,8 @@ model_update_tree_iter (GtkTreeModel *model, GtkTreeIter *iter, Task *task) vsz = g_format_size_full (task->vsz, G_FORMAT_SIZE_IEC_UNITS); rss = g_format_size_full (task->rss, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (value, 14, (more_precision) ? "%.2f" : "%.0f", task->cpu_user + task->cpu_system); - g_snprintf (cpu, 16, _("%s%%"), value); + g_snprintf (value, sizeof(value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system)); + g_snprintf (cpu, sizeof(cpu), _("%s%%"), value); /* Retrieve values for tweaking background/foreground color and updating content as needed */ gtk_tree_model_get (model, iter, XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, XTM_PTV_COLUMN_STATE, &old_state,