apply nibble patch removing per-item length limit
7ffe5198
1 file(s) · +14 −7
| 622 | 622 | void |
|
| 623 | 623 | readstdin(void) { |
|
| 624 | 624 | char *p, buf[1024]; |
|
| 625 | - | unsigned int len = 0, max = 0; |
|
| 625 | + | unsigned int len = 0, blen = 0, max = 0; |
|
| 626 | 626 | Item *i, *new; |
|
| 627 | 627 | ||
| 628 | - | i = NULL; |
|
| 628 | + | i = 0, p = NULL; |
|
| 629 | 629 | while(fgets(buf, sizeof buf, stdin)) { |
|
| 630 | - | len = strlen(buf); |
|
| 631 | - | if(buf[len-1] == '\n') |
|
| 632 | - | buf[--len] = '\0'; |
|
| 633 | - | if(!(p = strdup(buf))) |
|
| 634 | - | eprint("fatal: could not strdup() %u bytes\n", len); |
|
| 630 | + | len += (blen = strlen(buf)); |
|
| 631 | + | if(!(p = realloc(p, len))) { |
|
| 632 | + | eprint("fatal: could not realloc() %u bytes\n", len); |
|
| 633 | + | return; |
|
| 634 | + | } |
|
| 635 | + | memcpy (p + len - blen, buf, blen); |
|
| 636 | + | if (p[len - 1] == '\n') |
|
| 637 | + | p[len - 1] = 0; |
|
| 638 | + | else if (!feof(stdin)) |
|
| 639 | + | continue; |
|
| 635 | 640 | if(max < len) { |
|
| 636 | 641 | maxname = p; |
|
| 637 | 642 | max = len; |
|
| 638 | 643 | } |
|
| 644 | + | len = 0; |
|
| 639 | 645 | if(!(new = (Item *)malloc(sizeof(Item)))) |
|
| 640 | 646 | eprint("fatal: could not malloc() %u bytes\n", sizeof(Item)); |
|
| 641 | 647 | new->next = new->left = new->right = NULL; |
|
| 642 | 648 | new->text = p; |
|
| 649 | + | p = NULL; |
|
| 643 | 650 | if(!i) |
|
| 644 | 651 | allitems = new; |
|
| 645 | 652 | else |