[hackers] [st] Fixing bugs in the strtol and strtok_r replacements. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Tue, 26 Feb 2013 18:22:34 +0100

commit 7d32471efffa825f52d24930b5ee617105f9c83e
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Tue Feb 26 18:19:44 2013 +0100

    Fixing bugs in the strtol and strtok_r replacements.
    
    Thanks "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com> for the comments!

diff --git a/st.c b/st.c
index 7ddce0c..9f5793c 100644
--- a/st.c
+++ b/st.c
_AT_@ -1306,23 +1306,18 @@ csiparse(void) {
         }
 
         while(p < csiescseq.buf+csiescseq.len) {
- np = NULL;
                 v = strtol(p, &np, 10);
+ if(np == p)
+ break;
                 if(v == LONG_MAX || v == LONG_MIN)
                         v = -1;
- csiescseq.arg[csiescseq.narg] = v;
- if(np != NULL)
- p = np;
-
- if(*p == ';' && csiescseq.narg+1 < ESC_ARG_SIZ) {
- csiescseq.narg++, p++;
- } else {
- csiescseq.mode = *p;
- csiescseq.narg++;
-
- return;
- }
+ csiescseq.arg[csiescseq.narg++] = v;
+ p = np;
+ if(*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
+ break;
+ p++;
         }
+ csiescseq.mode = *p;
 }
 
 /* for absolute user moves, when decom is set */
_AT_@ -1930,16 +1925,13 @@ strhandle(void) {
 
 void
 strparse(void) {
- char *p = strescseq.buf, *np, *sp;
+ char *p = strescseq.buf, *sp;
 
- strescseq.narg = 0;
- np = strtok_r(strescseq.buf, ";", &sp);
- while(p < strescseq.buf+strescseq.len && np != NULL) {
+ strescseq.buf[strescseq.len] = '
Received on Tue Feb 26 2013 - 18:22:34 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 26 2013 - 18:24:06 CET