From a7dfcc17d5903ef66555067f6cd226afa0b5310b Mon Sep 17 00:00:00 2001 From: bakkeby Date: Tue, 27 Apr 2021 09:55:04 +0200 Subject: [PATCH] status2d: improving cut status line protection, dwm will still exit if an invalid color code comes through (there is an explicit die call in drw_clr_create) --- patch/bar_status2d.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/patch/bar_status2d.c b/patch/bar_status2d.c index e0d20a0..7784ac4 100644 --- a/patch/bar_status2d.c +++ b/patch/bar_status2d.c @@ -118,8 +118,9 @@ drawstatusbar(BarArg *a, char* stext) while (text[++i] != '^') { if (text[i] == 'c') { char buf[8]; - if (i + 7 > len) { + if (i + 7 >= len) { i += 7; + len = 0; break; } memcpy(buf, (char*)text+i+1, 7); @@ -134,8 +135,9 @@ drawstatusbar(BarArg *a, char* stext) i += 7; } else if (text[i] == 'b') { char buf[8]; - if (i + 7 > len) { + if (i + 7 >= len) { i += 7; + len = 0; break; } memcpy(buf, (char*)text+i+1, 7); @@ -204,11 +206,13 @@ drawstatusbar(BarArg *a, char* stext) text = text + i + 1; len -= i + 1; - i=-1; + i = -1; isCode = 0; + if (len <= 0) + break; } } - if (!isCode) { + if (!isCode && len > 0) { w = TEXTWM(text) - lrpad; drw_text(drw, x, y, w, bh, 0, text, 0, True); x += w; @@ -216,7 +220,7 @@ drawstatusbar(BarArg *a, char* stext) free(p); drw_setscheme(drw, scheme[SchemeNorm]); - return len - 1; + return 1; } int