X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=cad61bf6796907a1606c4a0aefe232277bff6650;hb=cdb3b1892af40110660da8c3f6fc06b1b054fd12;hp=4d543d19627f0e6dfb15b510ca4e8b46360987ee;hpb=c2026a495097a7e3bcfe4b58e1b9e393433cf150;p=st.git diff --git a/st.c b/st.c index 4d543d1..cad61bf 100644 --- a/st.c +++ b/st.c @@ -441,6 +441,7 @@ static int isfullutf8(char *, int); static ssize_t xwrite(int, char *, size_t); static void *xmalloc(size_t); static void *xrealloc(void *, size_t); +static char *xstrdup(char *s); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, @@ -529,6 +530,16 @@ xrealloc(void *p, size_t len) { return p; } +char * +xstrdup(char *s) { + char *p = strdup(s); + + if (!p) + die("Out of memory\n"); + + return p; +} + int utf8decode(char *s, long *u) { uchar c; @@ -953,11 +964,12 @@ selcopy(void) { /* append every set & selected glyph to the selection */ for(y = sel.nb.y; y < sel.ne.y + 1; y++) { gp = &term.line[y][0]; - last = gp + term.col; + last = &gp[term.col-1]; - while(--last >= gp && !(selected(last - gp, y) && \ - strcmp(last->c, " ") != 0)) - /* nothing */; + while(last >= gp && !(selected(last - gp, y) && + strcmp(last->c, " ") != 0)) { + --last; + } for(x = 0; gp <= last; x++, ++gp) { if(!selected(x, y) || (gp->mode & ATTR_WDUMMY)) @@ -2152,20 +2164,21 @@ csireset(void) { void strhandle(void) { char *p = NULL; - int i, j, narg; + int j, narg, par; strparse(); narg = strescseq.narg; + par = atoi(strescseq.args[0]); switch(strescseq.type) { case ']': /* OSC -- Operating System Command */ - switch(i = atoi(strescseq.args[0])) { + switch(par) { case 0: case 1: case 2: if(narg > 1) xsettitle(strescseq.args[1]); - break; + return; case 4: /* color set */ if(narg < 3) break; @@ -2182,25 +2195,20 @@ strhandle(void) { */ redraw(0); } - break; - default: - fprintf(stderr, "erresc: unknown str "); - strdump(); - break; + return; } break; case 'k': /* old title set compatibility */ xsettitle(strescseq.args[0]); - break; + return; case 'P': /* DSC -- Device Control String */ case '_': /* APC -- Application Program Command */ case '^': /* PM -- Privacy Message */ - default: - fprintf(stderr, "erresc: unknown str "); - strdump(); - /* die(""); */ - break; + return; } + + fprintf(stderr, "erresc: unknown str "); + strdump(); } void @@ -3792,7 +3800,7 @@ main(int argc, char *argv[]) { if(argc > 1) { opt_cmd = &argv[1]; if(argv[1] != NULL && opt_title == NULL) { - titles = strdup(argv[1]); + titles = xstrdup(argv[1]); opt_title = basename(titles); } }