diff --git a/src/ui/root.cc b/src/ui/root.cc index 9e18d289..84f942e3 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -354,8 +355,9 @@ Root::reset_input_history_attributes(ui::DownloadList::Input type) { void Root::set_input_history_size(int size) { - if (size < 1) - throw torrent::input_error("Invalid input history size."); + if (size < 1 || size > max_input_history_size) + throw torrent::input_error("Input history size must be between 1 and " + + std::to_string(max_input_history_size) + "."); for (auto& [entry, category] : m_input_history) { // Reserve the latest input history entries if new size is smaller than original. diff --git a/src/ui/root.h b/src/ui/root.h index 6f4d5717..b09bec1d 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -54,6 +54,11 @@ public: typedef std::vector InputHistoryCategory; typedef std::map InputHistory; + // Every category holds this many entries, and the whole history is written to + // and read back from the session, so the useful range ends long before the + // point where resizing it becomes a memory problem. + static constexpr int max_input_history_size = 4096; + Root(); void init(Control* c);