diff options
| -rw-r--r-- | dmenu.c | 11 |
1 files changed, 7 insertions, 4 deletions
| @@ -444,19 +444,22 @@ paste(void) { | |||
| 444 | 444 | ||
| 445 | void | 445 | void |
| 446 | readstdin(void) { | 446 | readstdin(void) { |
| 447 | char buf[sizeof text], *p; | 447 | char buf[sizeof text], *p, *maxstr = NULL; |
| 448 | size_t i, size = 0; | 448 | size_t i, max = 0, size = 0; |
| 449 | 449 | ||
| 450 | for(i = 0; fgets(buf, sizeof buf, stdin); items[++i].text = NULL) { | 450 | for(i = 0; fgets(buf, sizeof buf, stdin); items[++i].text = NULL) { |
| 451 | if(i+1 == size / sizeof *items || !items) | 451 | if(i+1 >= size / sizeof *items) |
| 452 | if(!(items = realloc(items, (size += BUFSIZ)))) | 452 | if(!(items = realloc(items, (size += BUFSIZ)))) |
| 453 | eprintf("cannot realloc %u bytes:", size); | 453 | eprintf("cannot realloc %u bytes:", size); |
| 454 | if((p = strchr(buf, '\n'))) | 454 | if((p = strchr(buf, '\n'))) |
| 455 | *p = '\0'; | 455 | *p = '\0'; |
| 456 | if(!(items[i].text = strdup(buf))) | 456 | if(!(items[i].text = strdup(buf))) |
| 457 | eprintf("cannot strdup %u bytes:", strlen(buf)+1); | 457 | eprintf("cannot strdup %u bytes:", strlen(buf)+1); |
| 458 | inputw = MAX(inputw, textw(dc, items[i].text)); | 458 | if(strlen(items[i].text) > max) |
| 459 | max = strlen(maxstr = items[i].text); | ||
| 459 | } | 460 | } |
| 461 | if(maxstr) | ||
| 462 | inputw = textw(dc, maxstr); | ||
| 460 | } | 463 | } |
| 461 | 464 | ||
| 462 | void | 465 | void |
