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; char *buf, *p;
#endif // SEPARATOR_PATCH | TSV_PATCH #endif // SEPARATOR_PATCH | TSV_PATCH
size_t size = 0; size_t i, junk, itemsiz = 0;
size_t i, junk;
ssize_t len; ssize_t len;
#if PASSWORD_PATCH #if PASSWORD_PATCH
@ -1441,9 +1440,11 @@ readstdin(void)
/* read each line from stdin and add it to the item list */ /* read each line from stdin and add it to the item list */
for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++) { for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++) {
if (i + 1 >= size / sizeof *items) if (i + 1 >= itemsiz) {
if (!(items = realloc(items, (size += BUFSIZ)))) itemsiz += 256;
die("cannot realloc %zu bytes:", size); if (!(items = realloc(items, itemsiz * sizeof(*items))))
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
}
if (line[len - 1] == '\n') if (line[len - 1] == '\n')
line[len - 1] = '\0'; line[len - 1] = '\0';