Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2026-02-05 - Masked Global Variables in C
**Learning:** The global variable `stext` is masked by a function argument of the same name in `drawstatusbar(..., char *stext)`. This requires careful inspection of variable scope when optimizing, as `sizeof(stext)` yields different results (pointer size vs array size) depending on the scope.
**Action:** Always verify variable declarations and scope before applying size-based optimizations or `sizeof` checks in C codebases.
10 changes: 8 additions & 2 deletions bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
char *text;
char *p;

char buf[1024];

len = strlen(stext) + 1;
if (!(text = (char *)malloc(sizeof(char) * len))) {
if (len < sizeof(buf)) {
text = buf;
} else if (!(text = (char *)malloc(sizeof(char) * len))) {
die("malloc");
}
p = text;
Expand Down Expand Up @@ -194,7 +198,9 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
}

drw_setscheme(drw, statusscheme);
free(p);
if (p != buf) {
free(p);
}

return ret;
}
Expand Down