diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 6b0f60e..30cceaa 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -141,7 +141,7 @@ struct DropdownWindow : Window { } /* Capacity is the average number of items visible */ - this->vscroll->SetCapacity(size.height * (uint16)list->Length() / list_height); + this->vscroll->SetCapacity(size.height * (uint16)list->Length() / max(1, list_height)); this->vscroll->SetCount((uint16)list->Length()); this->parent_wnd_class = parent->window_class; @@ -373,8 +373,8 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b } else { /* ... and lastly if it won't, enable the scroll bar and fit the * list in below the widget */ - int avg_height = list_height / (int)list->Length(); - int rows = (screen_bottom - 4 - top) / avg_height; + int avg_height = list_height / max((int)list->Length(), 1); + int rows = (screen_bottom - 4 - top) / max(avg_height, 1); height = rows * avg_height; scroll = true; /* Add space for the scroll bar if we automatically determined