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:
bakkeby 2023-04-07 14:15:31 +02:00
parent be4a165539
commit 1279886b9c

11
dmenu.c
View File

@ -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';