changeset 2325:c5665d3191aa

Prevent assigning negative values to unsigned variables
author Michał Kępień <bitbucket@kempniu.pl>
date Mon, 24 Sep 2018 21:04:09 +0200
parents 4ddd6f5c3ffc
children 54b4272de463
files mcabber/mcabber/screen.c
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/screen.c	Sun Sep 23 22:52:29 2018 +0200
+++ b/mcabber/mcabber/screen.c	Mon Sep 24 21:04:09 2018 +0200
@@ -917,7 +917,8 @@
 
 guint scr_gettextwidth(void)
 {
-  return maxX - Roster_Width - scr_getprefixwidth();
+  int used_width = Roster_Width + scr_getprefixwidth();
+  return maxX > used_width ? maxX - used_width : 0;
 }
 
 guint scr_gettextheight(void)
@@ -1094,8 +1095,7 @@
     g_free(id);
   } else {  // Load buddy history from file (if enabled)
     tmp->bd = g_new0(buffdata, 1);
-    hlog_read_history(title, &tmp->bd->hbuf,
-                      maxX - Roster_Width - scr_getprefixwidth());
+    hlog_read_history(title, &tmp->bd->hbuf, scr_gettextwidth());
 
     // Set a readmark to separate new content
     hbuf_set_readmark(tmp->bd->hbuf, TRUE);
@@ -1536,8 +1536,7 @@
     g_free(nicktmp);
   }
   hbuf_add_line(&win_entry->bd->hbuf, text_locale, timestamp, prefix_flags,
-                maxX - Roster_Width - scr_getprefixwidth(), num_history_blocks,
-                mucnicklen, xep184);
+                scr_gettextwidth(), num_history_blocks, mucnicklen, xep184);
   g_free(text_locale);
 
   if (win_entry->bd->cleared) {