Fix stdin read.

This commit is contained in:
Jari Vetoniemi 2014-10-25 17:18:41 +03:00
parent b03cd1ea53
commit 2820734ec0

View File

@ -234,10 +234,14 @@ read_items_to_menu_from_stdin(struct bm_menu *menu)
}
buffer[allocated - step + read - 1] = 0;
size_t pos;
char *s = buffer;
while ((pos = strcspn(s, "\n")) != 0) {
size_t next = pos + (s[pos] != 0);
while ((size_t)(s - buffer) < allocated - step + read) {
size_t pos = strcspn(s, "\n");
if (pos == 0) {
s += 1;
continue;
}
s[pos] = 0;
struct bm_item *item;
@ -245,7 +249,7 @@ read_items_to_menu_from_stdin(struct bm_menu *menu)
break;
bm_menu_add_item(menu, item);
s += next;
s += pos + 1;
}
free(buffer);