aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2013-02-26 18:19:44 +0100
committerChristoph Lohmann <20h@r-36.net>2013-02-26 18:19:44 +0100
commit7d32471efffa825f52d24930b5ee617105f9c83e (patch)
tree1f41bfde8b4eac27473d78e9b60ede16ee1b0354
parent7cb0d95509d1b2837e4fa7d131f497800b20d22c (diff)
downloadst-patched-7d32471efffa825f52d24930b5ee617105f9c83e.tar.bz2
st-patched-7d32471efffa825f52d24930b5ee617105f9c83e.tar.xz
st-patched-7d32471efffa825f52d24930b5ee617105f9c83e.zip
Fixing bugs in the strtol and strtok_r replacements.
Thanks "Roberto E. Vargas Caballero" <k0ga@shike2.com> for the comments!
-rw-r--r--st.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/st.c b/st.c
index 7ddce0c..9f5793c 100644
--- a/st.c
+++ b/st.c
@@ -1306,23 +1306,18 @@ csiparse(void) {
1306 } 1306 }
1307 1307
1308 while(p < csiescseq.buf+csiescseq.len) { 1308 while(p < csiescseq.buf+csiescseq.len) {
1309 np = NULL;
1310 v = strtol(p, &np, 10); 1309 v = strtol(p, &np, 10);
1310 if(np == p)
1311 break;
1311 if(v == LONG_MAX || v == LONG_MIN) 1312 if(v == LONG_MAX || v == LONG_MIN)
1312 v = -1; 1313 v = -1;
1313 csiescseq.arg[csiescseq.narg] = v; 1314 csiescseq.arg[csiescseq.narg++] = v;
1314 if(np != NULL) 1315 p = np;
1315 p = np; 1316 if(*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
1316 1317 break;
1317 if(*p == ';' && csiescseq.narg+1 < ESC_ARG_SIZ) { 1318 p++;
1318 csiescseq.narg++, p++;
1319 } else {
1320 csiescseq.mode = *p;
1321 csiescseq.narg++;
1322
1323 return;
1324 }
1325 } 1319 }
1320 csiescseq.mode = *p;
1326} 1321}
1327 1322
1328/* for absolute user moves, when decom is set */ 1323/* for absolute user moves, when decom is set */
@@ -1930,16 +1925,13 @@ strhandle(void) {
1930 1925
1931void 1926void
1932strparse(void) { 1927strparse(void) {
1933 char *p = strescseq.buf, *np, *sp; 1928 char *p = strescseq.buf, *sp;
1934 1929
1935 strescseq.narg = 0; 1930 strescseq.buf[strescseq.len] = '\0';
1936 np = strtok_r(strescseq.buf, ";", &sp); 1931 for(p = strtok_r(p, ";", &sp); p; p = strtok_r(NULL, ";", &sp)) {
1937 while(p < strescseq.buf+strescseq.len && np != NULL) { 1932 if(strescseq.narg == STR_ARG_SIZ)
1933 return;
1938 strescseq.args[strescseq.narg++] = p; 1934 strescseq.args[strescseq.narg++] = p;
1939
1940 np = strtok_r(NULL, ";", &sp);
1941 if(np != NULL)
1942 p = np;
1943 } 1935 }
1944} 1936}
1945 1937
@@ -1951,7 +1943,9 @@ strdump(void) {
1951 printf("ESC%c", strescseq.type); 1943 printf("ESC%c", strescseq.type);
1952 for(i = 0; i < strescseq.len; i++) { 1944 for(i = 0; i < strescseq.len; i++) {
1953 c = strescseq.buf[i] & 0xff; 1945 c = strescseq.buf[i] & 0xff;
1954 if(isprint(c)) { 1946 if(c == '\0') {
1947 return;
1948 } else if(isprint(c)) {
1955 putchar(c); 1949 putchar(c);
1956 } else if(c == '\n') { 1950 } else if(c == '\n') {
1957 printf("(\\n)"); 1951 printf("(\\n)");
@@ -2039,7 +2033,7 @@ tputc(char *c, int len) {
2039 strhandle(); 2033 strhandle();
2040 break; 2034 break;
2041 default: 2035 default:
2042 if(strescseq.len + len < sizeof(strescseq.buf)) { 2036 if(strescseq.len + len < sizeof(strescseq.buf) - 1) {
2043 memmove(&strescseq.buf[strescseq.len], c, len); 2037 memmove(&strescseq.buf[strescseq.len], c, len);
2044 strescseq.len += len; 2038 strescseq.len += len;
2045 } else { 2039 } else {