AmendHub

Download:

jcs

/

wallops

/

amendments

/

66

chatter: Cast BitMap rowBytes to long to avoid overflowing a short

Show an error when we fail.

jcs made amendment 66 2 months ago
--- chatter.c Fri Sep 6 11:45:04 2024 +++ chatter.c Sun Sep 8 16:07:36 2024 @@ -89,11 +89,13 @@ chatter_init(const char *server, const unsigned short width = screenBits.bounds.right - screenBits.bounds.left; height = screenBits.bounds.bottom - screenBits.bounds.top; chatter->shadow.rowBytes = (((width - 1) / 16) + 1) * 2; - chatter->shadow.baseAddr = xmalloczero(chatter->shadow.rowBytes * - height); + chatter->shadow.baseAddr = + xmalloczero((long)chatter->shadow.rowBytes * height); if (chatter->shadow.baseAddr == NULL) { xfree(&chatter); xfree(&focusable); + warn("malloc(%ld) failed", + (long)(chatter->shadow.rowBytes * height)); return NULL; } @@ -234,6 +236,8 @@ chatter_add_tab(struct chatter *chatter, Rect *win_bou win_bounds = &chatter->win->portRect; tab = xmalloczero(sizeof(struct chatter_tab)); + if (tab == NULL) + panic("xmalloc failed: out of memory"); SLIST_APPEND(&chatter->tabs_list, tab, chatter_tab, list); tab->index = chatter->ntabs++; tab->conn = conn; @@ -566,7 +570,10 @@ chatter_draw_tab_bar(struct chatter *chatter) width = chatter->win->portRect.right - chatter->win->portRect.left; chatter->tab_bar.rowBytes = (((width - 1) / 16) + 1) * 2; chatter->tab_bar.baseAddr = xmalloczero( - chatter->tab_bar.rowBytes * TAB_BAR_HEIGHT); + (long)chatter->tab_bar.rowBytes * TAB_BAR_HEIGHT); + if (chatter->tab_bar.baseAddr == NULL) + panic("malloc(%ld) failed: out of memory", + (long)chatter->tab_bar.rowBytes * TAB_BAR_HEIGHT); SetRect(&chatter->tab_bar.bounds, 0, 0, width, TAB_BAR_HEIGHT); }