Skip to content

Commit edda4df

Browse files
committed
Improve ScreenManager_drawScreenTabs() logic on screen width
Make the code more robust with very small width of the terminal screen. Also add assertions on x positions in the drawTab() subroutine.
1 parent a270702 commit edda4df

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

ScreenManager.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
161161
}
162162

163163
static inline bool drawTab(const int* y, int* x, int l, const char* name, bool cur) {
164+
assert(*x >= 0);
165+
assert(*x < l);
166+
164167
attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]);
165168
mvaddch(*y, *x, '[');
166169
(*x)++;
@@ -190,9 +193,12 @@ static void ScreenManager_drawScreenTabs(ScreenManager* this) {
190193
int y = panel->y - 1;
191194
int x = SCREEN_TAB_MARGIN_LEFT;
192195

196+
if (x >= l)
197+
goto end;
198+
193199
if (this->name) {
194200
drawTab(&y, &x, l, this->name, true);
195-
return;
201+
goto end;
196202
}
197203

198204
for (int s = 0; screens[s]; s++) {
@@ -201,6 +207,8 @@ static void ScreenManager_drawScreenTabs(ScreenManager* this) {
201207
break;
202208
}
203209
}
210+
211+
end:
204212
attrset(CRT_colors[RESET_COLOR]);
205213
}
206214

0 commit comments

Comments
 (0)