From 8b562109634b8e42226022c61399c29f737d2155 Mon Sep 17 00:00:00 2001 From: Maxime Schmitt Date: Sun, 22 Sep 2019 14:22:30 +0200 Subject: [PATCH] Fix: Window location code This bug happens when additional plot stacks get allocated when there is enough room in the terminal. An integer division rounding leads to some location to be skipped. --- src/interface_layout_selection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface_layout_selection.c b/src/interface_layout_selection.c index f35ec8f..76d2544 100644 --- a/src/interface_layout_selection.c +++ b/src/interface_layout_selection.c @@ -165,12 +165,12 @@ void compute_sizes_from_layout( if (*num_plots == 0) { *plot_positions = NULL; } else { - *plot_positions = malloc(*num_plots * sizeof(**plot_positions)); + *plot_positions = calloc(*num_plots, sizeof(**plot_positions)); *plot_types = preferred_plot_type; unsigned rows_per_stack = rows_left / num_plot_stacks; if (rows_per_stack > 23) rows_per_stack = 23; - unsigned plot_per_row = *num_plots / num_plot_stacks; + unsigned plot_per_row = (*num_plots + (*num_plots % num_plot_stacks)) / num_plot_stacks; unsigned num_plot_done = 0; unsigned currentPosX = 0, currentPosY = rows_for_header; for (unsigned i = 0; i < num_plot_stacks; ++i) {