suckless-tools
Home of dwm, dmenu and other quality software with a focus on simplicity, clarity, and frugality.
Home page: http://suckless.org
Log
- Started: 2012-01-31
- Discussed: 2012-01-31
- Draft Submitted: 2012-02-01
- Submitted: 2012-02-02, Bug#658386
- Accepted: 2012-11-15, by Vasudev Kamath
ToDo
Here is the output of grep -R PATH_MAX suckless-tools-38/*
:
dmenu/dmenu_path.c: char buf[PATH_MAX];
Comments
Here are comments on the patch...
void
scan(void) {
- char buf[PATH_MAX];
+ char *buf = NULL;
+ char *new_buf = NULL;
+ size_t buf_size = 0;
In this function we turn buf
into dynamically allocated string.
while((ent = readdir(dp))) {
+ buf_size = strlen(dir)+strlen(ent->d_name)+2;
+ if(!buf || strlen(buf) < buf_size) {
+ new_buf = realloc(buf, buf_size);
+ if(!new_buf)
+ die("realloc failed");
+ buf = new_buf;
+ }
For each directory entry we create or adapt the buffer size.
}
+ free(buf);
We free the buf when done.