goptions: ensure that FIO_OPT_STR_VAL doesn't exceed max multiplier
[fio.git] / goptions.c
index 30edd5cdac6e3fd8545063b7682f21afb9576aaa..f1148bf44884578948db36adf6fc26d31b9a882e 100644 (file)
@@ -43,6 +43,7 @@ struct gopt_str_val {
        struct gopt gopt;
        GtkWidget *spin;
        GtkWidget *combo;
+       unsigned int maxindex;
 };
 
 #define GOPT_RANGE_SPIN        4
@@ -601,9 +602,12 @@ static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
         * Can't rely on exact value, as fast changes increment >= 1
         */
        if (!val) {
-               val = 1;
                index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
-               gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               if (index + 1 <= g->maxindex) {
+                       val = 1;
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               } else
+                       val = 1023;
                gtk_spin_button_set_value(spin, val);
        } else {
                index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
@@ -644,6 +648,7 @@ static struct gopt *gopt_new_str_val(struct fio_option *o,
                gtk_combo_box_append_text(GTK_COMBO_BOX(g->combo), postfix[i]);
                i++;
        }
+       g->maxindex = i - 1;
        gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
        gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3);