diff options
author | Christoph Lohmann <20h@r-36.net> | 2013-02-26 21:43:40 +0100 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2013-02-26 21:43:40 +0100 |
commit | c6b89f23e7546c30dea42a3c49f99682c5818190 (patch) | |
tree | dc2f411410882c2c8b2abc95189ecc830704d09e | |
parent | 1c1621da699adae49a4344b145f856dacb57270c (diff) | |
download | st-patched-c6b89f23e7546c30dea42a3c49f99682c5818190.tar.bz2 st-patched-c6b89f23e7546c30dea42a3c49f99682c5818190.tar.xz st-patched-c6b89f23e7546c30dea42a3c49f99682c5818190.zip |
Using strsep and fixing null termination in csiparse.
Thanks for the hint from Alexander Sedov <alex0player@gmail.com>!
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | st.c | 15 |
2 files changed, 8 insertions, 9 deletions
@@ -19,7 +19,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext -lXft \ | |||
19 | $(shell pkg-config --libs freetype2) | 19 | $(shell pkg-config --libs freetype2) |
20 | 20 | ||
21 | # flags | 21 | # flags |
22 | CPPFLAGS = -DVERSION=\"${VERSION}\" | 22 | CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_XOPEN_SOURCE=600 |
23 | CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} | 23 | CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} |
24 | LDFLAGS += -g ${LIBS} | 24 | LDFLAGS += -g ${LIBS} |
25 | 25 | ||
@@ -1,5 +1,4 @@ | |||
1 | /* See LICENSE for licence details. */ | 1 | /* See LICENSE for licence details. */ |
2 | #define _XOPEN_SOURCE 600 | ||
3 | #include <ctype.h> | 2 | #include <ctype.h> |
4 | #include <errno.h> | 3 | #include <errno.h> |
5 | #include <fcntl.h> | 4 | #include <fcntl.h> |
@@ -1304,6 +1303,7 @@ csiparse(void) { | |||
1304 | p++; | 1303 | p++; |
1305 | } | 1304 | } |
1306 | 1305 | ||
1306 | csiescseq.buf[csiescseq.len] = '\0'; | ||
1307 | while(p < csiescseq.buf+csiescseq.len) { | 1307 | while(p < csiescseq.buf+csiescseq.len) { |
1308 | np = NULL; | 1308 | np = NULL; |
1309 | v = strtol(p, &np, 10); | 1309 | v = strtol(p, &np, 10); |
@@ -1925,14 +1925,12 @@ strhandle(void) { | |||
1925 | 1925 | ||
1926 | void | 1926 | void |
1927 | strparse(void) { | 1927 | strparse(void) { |
1928 | char *p = strescseq.buf, *sp; | 1928 | char *p = strescseq.buf; |
1929 | 1929 | ||
1930 | strescseq.narg = 0; | ||
1930 | strescseq.buf[strescseq.len] = '\0'; | 1931 | strescseq.buf[strescseq.len] = '\0'; |
1931 | for(p = strtok_r(p, ";", &sp); p; p = strtok_r(NULL, ";", &sp)) { | 1932 | while(p && strescseq.narg < STR_ARG_SIZ) |
1932 | if(strescseq.narg == STR_ARG_SIZ) | 1933 | strescseq.args[strescseq.narg++] = strsep(&p, ";"); |
1933 | return; | ||
1934 | strescseq.args[strescseq.narg++] = p; | ||
1935 | } | ||
1936 | } | 1934 | } |
1937 | 1935 | ||
1938 | void | 1936 | void |
@@ -2109,7 +2107,8 @@ tputc(char *c, int len) { | |||
2109 | if(term.esc & ESC_CSI) { | 2107 | if(term.esc & ESC_CSI) { |
2110 | csiescseq.buf[csiescseq.len++] = ascii; | 2108 | csiescseq.buf[csiescseq.len++] = ascii; |
2111 | if(BETWEEN(ascii, 0x40, 0x7E) | 2109 | if(BETWEEN(ascii, 0x40, 0x7E) |
2112 | || csiescseq.len >= ESC_BUF_SIZ) { | 2110 | || csiescseq.len >= \ |
2111 | sizeof(csiescseq.buf)-1) { | ||
2113 | term.esc = 0; | 2112 | term.esc = 0; |
2114 | csiparse(); | 2113 | csiparse(); |
2115 | csihandle(); | 2114 | csihandle(); |