mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 14:05:48 +02:00
Bump to ba1a347.
readstdin: allocate amount of items Keep track of the amount of items (not a total buffer size), allocate an array of new items. For now change BUFSIZ bytes to 256 * sizeof(struct item)). Ref. https://git.suckless.org/dmenu/commit/ba1a347dcaba055f824161007dfee60db3ea785b.html
This commit is contained in:
parent
be4a165539
commit
1279886b9c
11
dmenu.c
11
dmenu.c
@ -1428,8 +1428,7 @@ readstdin(void)
|
||||
char *buf, *p;
|
||||
#endif // SEPARATOR_PATCH | TSV_PATCH
|
||||
|
||||
size_t size = 0;
|
||||
size_t i, junk;
|
||||
size_t i, junk, itemsiz = 0;
|
||||
ssize_t len;
|
||||
|
||||
#if PASSWORD_PATCH
|
||||
@ -1441,9 +1440,11 @@ readstdin(void)
|
||||
|
||||
/* read each line from stdin and add it to the item list */
|
||||
for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++) {
|
||||
if (i + 1 >= size / sizeof *items)
|
||||
if (!(items = realloc(items, (size += BUFSIZ))))
|
||||
die("cannot realloc %zu bytes:", size);
|
||||
if (i + 1 >= itemsiz) {
|
||||
itemsiz += 256;
|
||||
if (!(items = realloc(items, itemsiz * sizeof(*items))))
|
||||
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
|
||||
}
|
||||
if (line[len - 1] == '\n')
|
||||
line[len - 1] = '\0';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user