commit c6b89f23e7546c30dea42a3c49f99682c5818190 from: Christoph Lohmann <20h@r-36.net> date: Tue Feb 26 20:43:40 2013 UTC Using strsep and fixing null termination in csiparse. Thanks for the hint from Alexander Sedov ! commit - 1c1621da699adae49a4344b145f856dacb57270c commit + c6b89f23e7546c30dea42a3c49f99682c5818190 blob - ecc5c833989b5fbb4d50aaa6f528acc0c3ff7395 blob + abf25c12b27cf9dcfaa646b1b80d25ce43c3ff7f --- config.mk +++ config.mk @@ -19,7 +19,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext $(shell pkg-config --libs freetype2) # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_XOPEN_SOURCE=600 CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS += -g ${LIBS} blob - 8b5ba644af423de6932eec728ccf475d63e3761d blob + fc9ed70d435c03434e5a1fb64898a667d5b4caeb --- st.c +++ st.c @@ -1,5 +1,4 @@ /* See LICENSE for licence details. */ -#define _XOPEN_SOURCE 600 #include #include #include @@ -1304,6 +1303,7 @@ csiparse(void) { p++; } + csiescseq.buf[csiescseq.len] = '\0'; while(p < csiescseq.buf+csiescseq.len) { np = NULL; v = strtol(p, &np, 10); @@ -1925,14 +1925,12 @@ strhandle(void) { void strparse(void) { - char *p = strescseq.buf, *sp; + char *p = strescseq.buf; + strescseq.narg = 0; strescseq.buf[strescseq.len] = '\0'; - for(p = strtok_r(p, ";", &sp); p; p = strtok_r(NULL, ";", &sp)) { - if(strescseq.narg == STR_ARG_SIZ) - return; - strescseq.args[strescseq.narg++] = p; - } + while(p && strescseq.narg < STR_ARG_SIZ) + strescseq.args[strescseq.narg++] = strsep(&p, ";"); } void @@ -2109,7 +2107,8 @@ tputc(char *c, int len) { if(term.esc & ESC_CSI) { csiescseq.buf[csiescseq.len++] = ascii; if(BETWEEN(ascii, 0x40, 0x7E) - || csiescseq.len >= ESC_BUF_SIZ) { + || csiescseq.len >= \ + sizeof(csiescseq.buf)-1) { term.esc = 0; csiparse(); csihandle();