diff --git a/chatclient-cli.c b/chatclient-cli.c index 74f2cbc..d600900 100755 --- a/chatclient-cli.c +++ b/chatclient-cli.c @@ -206,11 +206,16 @@ static void cc_render_message_field( const unsigned int inner_w = w - x - 2; const unsigned int inner_h = h - y - 2; - const int max_offset = messages.size > inner_h ? messages.size - inner_h : 0; - if (render_state.scroll_offset > max_offset) render_state.scroll_offset = max_offset; + int max_offset = messages.size > inner_h ? messages.size - inner_h : 0; + if (render_state.scroll_offset > max_offset) + render_state.scroll_offset = max_offset; + if (render_state.scroll_offset < 0) + render_state.scroll_offset = 0; - const int last = messages.size - render_state.scroll_offset; - const int first = last - inner_h > 0 ? last - inner_h : 0; + int last = messages.size - render_state.scroll_offset; + if (last < 0) last = 0; + int first = last - inner_h; + if (first < 0) first = 0; for (int i = first; i < last; i++) { mvprintw(y + 1 + (i - first), x + 1, "%-*.*s", inner_w, inner_w, messages.data[i]);