diff options
| -rw-r--r-- | st.c | 44 |
1 files changed, 31 insertions, 13 deletions
| @@ -326,6 +326,9 @@ static int utf8encode(long *, char *); | |||
| 326 | static int utf8size(char *); | 326 | static int utf8size(char *); |
| 327 | static int isfullutf8(char *, int); | 327 | static int isfullutf8(char *, int); |
| 328 | 328 | ||
| 329 | static void *xmalloc(size_t); | ||
| 330 | static void *xrealloc(void *, size_t); | ||
| 331 | |||
| 329 | static void (*handler[LASTEvent])(XEvent *) = { | 332 | static void (*handler[LASTEvent])(XEvent *) = { |
| 330 | [KeyPress] = kpress, | 333 | [KeyPress] = kpress, |
| 331 | [ClientMessage] = cmessage, | 334 | [ClientMessage] = cmessage, |
| @@ -359,6 +362,21 @@ static char *opt_title = NULL; | |||
| 359 | static char *opt_embed = NULL; | 362 | static char *opt_embed = NULL; |
| 360 | static char *opt_class = NULL; | 363 | static char *opt_class = NULL; |
| 361 | 364 | ||
| 365 | void * | ||
| 366 | xmalloc(size_t len) { | ||
| 367 | void *p = malloc(len); | ||
| 368 | if(!p) | ||
| 369 | die("Out of memory"); | ||
| 370 | return p; | ||
| 371 | } | ||
| 372 | |||
| 373 | void * | ||
| 374 | xrealloc(void *p, size_t len) { | ||
| 375 | if((p = realloc(p, len)) == NULL) | ||
| 376 | die("Out of memory"); | ||
| 377 | return p; | ||
| 378 | } | ||
| 379 | |||
| 362 | int | 380 | int |
| 363 | utf8decode(char *s, long *u) { | 381 | utf8decode(char *s, long *u) { |
| 364 | uchar c; | 382 | uchar c; |
| @@ -565,7 +583,7 @@ selcopy(void) { | |||
| 565 | 583 | ||
| 566 | else { | 584 | else { |
| 567 | bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ; | 585 | bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ; |
| 568 | ptr = str = malloc(bufsize); | 586 | ptr = str = xmalloc(bufsize); |
| 569 | 587 | ||
| 570 | /* append every set & selected glyph to the selection */ | 588 | /* append every set & selected glyph to the selection */ |
| 571 | for(y = 0; y < term.row; y++) { | 589 | for(y = 0; y < term.row; y++) { |
| @@ -918,14 +936,14 @@ void | |||
| 918 | tnew(int col, int row) { | 936 | tnew(int col, int row) { |
| 919 | /* set screen size */ | 937 | /* set screen size */ |
| 920 | term.row = row, term.col = col; | 938 | term.row = row, term.col = col; |
| 921 | term.line = malloc(term.row * sizeof(Line)); | 939 | term.line = xmalloc(term.row * sizeof(Line)); |
| 922 | term.alt = malloc(term.row * sizeof(Line)); | 940 | term.alt = xmalloc(term.row * sizeof(Line)); |
| 923 | term.dirty = malloc(term.row * sizeof(*term.dirty)); | 941 | term.dirty = xmalloc(term.row * sizeof(*term.dirty)); |
| 924 | term.tabs = malloc(term.col * sizeof(*term.tabs)); | 942 | term.tabs = xmalloc(term.col * sizeof(*term.tabs)); |
| 925 | 943 | ||
| 926 | for(row = 0; row < term.row; row++) { | 944 | for(row = 0; row < term.row; row++) { |
| 927 | term.line[row] = malloc(term.col * sizeof(Glyph)); | 945 | term.line[row] = xmalloc(term.col * sizeof(Glyph)); |
| 928 | term.alt [row] = malloc(term.col * sizeof(Glyph)); | 946 | term.alt [row] = xmalloc(term.col * sizeof(Glyph)); |
| 929 | term.dirty[row] = 0; | 947 | term.dirty[row] = 0; |
| 930 | } | 948 | } |
| 931 | memset(term.tabs, 0, term.col * sizeof(*term.tabs)); | 949 | memset(term.tabs, 0, term.col * sizeof(*term.tabs)); |
| @@ -1761,16 +1779,16 @@ tresize(int col, int row) { | |||
| 1761 | } | 1779 | } |
| 1762 | 1780 | ||
| 1763 | /* resize to new height */ | 1781 | /* resize to new height */ |
| 1764 | term.line = realloc(term.line, row * sizeof(Line)); | 1782 | term.line = xrealloc(term.line, row * sizeof(Line)); |
| 1765 | term.alt = realloc(term.alt, row * sizeof(Line)); | 1783 | term.alt = xrealloc(term.alt, row * sizeof(Line)); |
| 1766 | term.dirty = realloc(term.dirty, row * sizeof(*term.dirty)); | 1784 | term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty)); |
| 1767 | term.tabs = realloc(term.tabs, col * sizeof(*term.tabs)); | 1785 | term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs)); |
| 1768 | 1786 | ||
| 1769 | /* resize each row to new width, zero-pad if needed */ | 1787 | /* resize each row to new width, zero-pad if needed */ |
| 1770 | for(i = 0; i < minrow; i++) { | 1788 | for(i = 0; i < minrow; i++) { |
| 1771 | term.dirty[i] = 1; | 1789 | term.dirty[i] = 1; |
| 1772 | term.line[i] = realloc(term.line[i], col * sizeof(Glyph)); | 1790 | term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); |
| 1773 | term.alt[i] = realloc(term.alt[i], col * sizeof(Glyph)); | 1791 | term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph)); |
| 1774 | for(x = mincol; x < col; x++) { | 1792 | for(x = mincol; x < col; x++) { |
| 1775 | term.line[i][x].state = 0; | 1793 | term.line[i][x].state = 0; |
| 1776 | term.alt[i][x].state = 0; | 1794 | term.alt[i][x].state = 0; |
