diff options
author | musil <tmusil@users.sourceforge.net> | 2006-11-21 14:43:21 +0000 |
---|---|---|
committer | musil <tmusil@users.sourceforge.net> | 2006-11-21 14:43:21 +0000 |
commit | 93bc365d590757919a53fea685876fd28d9d06aa (patch) | |
tree | b5c15a86854d9c34bbcea88e7aa84a3b6fe26134 /src/iemlib2 | |
parent | a9b5904826c3981234eda971a3a8043d5c771029 (diff) |
fixed this bug with MAXPDSTRING memory allocation
svn path=/trunk/externals/iemlib/; revision=6357
Diffstat (limited to 'src/iemlib2')
-rw-r--r-- | src/iemlib2/mergefilename.c | 2 | ||||
-rw-r--r-- | src/iemlib2/splitfilename.c | 22 | ||||
-rw-r--r-- | src/iemlib2/stripfilename.c | 29 |
3 files changed, 24 insertions, 29 deletions
diff --git a/src/iemlib2/mergefilename.c b/src/iemlib2/mergefilename.c index ddf06ff..19edc0d 100644 --- a/src/iemlib2/mergefilename.c +++ b/src/iemlib2/mergefilename.c @@ -20,7 +20,7 @@ typedef struct _mergefilename { t_object x_obj; char x_sep[2]; - char x_mem[MAXPDSTRING]; /* miller WHY ???? */ + char x_mem[MAXPDSTRING]; } t_mergefilename; static void mergefilename_separator(t_mergefilename *x, t_symbol *s, int ac, t_atom *av) diff --git a/src/iemlib2/splitfilename.c b/src/iemlib2/splitfilename.c index 5646178..a4b7cbf 100644 --- a/src/iemlib2/splitfilename.c +++ b/src/iemlib2/splitfilename.c @@ -20,7 +20,7 @@ typedef struct _splitfilename { t_object x_obj; char x_sep[2]; - char *x_mem; + char x_mem[MAXPDSTRING]; t_int x_size; t_outlet *x_outpath; t_outlet *x_outfile; @@ -77,13 +77,12 @@ static void splitfilename_symbol(t_splitfilename *x, t_symbol *s) if(x->x_sep[0]) { char *sep_ptr=x->x_mem; - - if(length > x->x_size) - { - x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), (length+100)*sizeof(char)); - x->x_size = length + 100; - } - strcpy(x->x_mem, s->s_name); + + if(length > (MAXPDSTRING - 2)) + strncpy(x->x_mem, s->s_name, MAXPDSTRING - 2 - length); + else + strcpy(x->x_mem, s->s_name); + sep_ptr = strrchr(x->x_mem, x->x_sep[0]);/* points to the leftest separator-char-index of string */ if((!sep_ptr) || ((sep_ptr - x->x_mem) < 0) || ((sep_ptr - x->x_mem) >= length)) { /* JMZ: 20050701 : removed typecast (char*) to (int); this is not portable */ @@ -106,11 +105,6 @@ static void splitfilename_symbol(t_splitfilename *x, t_symbol *s) } } -static void splitfilename_free(t_splitfilename *x) -{ - freebytes(x->x_mem, x->x_size*sizeof(char)); -} - static void *splitfilename_new(t_symbol *s, int ac, t_atom *av) { t_splitfilename *x = (t_splitfilename *)pd_new(splitfilename_class); @@ -121,8 +115,6 @@ static void *splitfilename_new(t_symbol *s, int ac, t_atom *av) x->x_sep[0] = '/'; else splitfilename_separator(x, s, ac, av); - x->x_size = 400; - x->x_mem = (char *)getbytes(x->x_size*sizeof(char)); x->x_outpath = (t_outlet *)outlet_new(&x->x_obj, &s_symbol); x->x_outfile = (t_outlet *)outlet_new(&x->x_obj, &s_symbol); return (x); diff --git a/src/iemlib2/stripfilename.c b/src/iemlib2/stripfilename.c index 82dc70b..c6e4f2c 100644 --- a/src/iemlib2/stripfilename.c +++ b/src/iemlib2/stripfilename.c @@ -17,34 +17,37 @@ typedef struct _stripfilename { t_object x_obj; int x_nr_char; + char x_mem[MAXPDSTRING]; } t_stripfilename; static void stripfilename_symbol(t_stripfilename *x, t_symbol *s) { - if(x->x_nr_char < 0) + if(x->x_nr_char < 0)/* cuts the string from the back */ { int len = strlen(s->s_name); - char *str=(char *)getbytes((len+2)*sizeof(char)); int i=len + x->x_nr_char; - - strcpy(str, s->s_name); + + if(len > (MAXPDSTRING - 2)) + strncpy(x->x_mem, s->s_name, MAXPDSTRING - 2 - len); + else + strcpy(x->x_mem, s->s_name); if(i < 0) i = 0; - str[i] = 0; - outlet_symbol(x->x_obj.ob_outlet, gensym(str)); - freebytes(str, (len+2)*sizeof(char)); + x->x_mem[i] = 0; + outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_mem)); } - else if(x->x_nr_char > 0) + else if(x->x_nr_char > 0)/* starts the string at this new offset */ { int len = strlen(s->s_name); - char *str=(char *)getbytes((len+2)*sizeof(char)); int i=x->x_nr_char; - - strcpy(str, s->s_name); + + if(len > (MAXPDSTRING - 2)) + strncpy(x->x_mem, s->s_name, MAXPDSTRING - 2 - len); + else + strcpy(x->x_mem, s->s_name); if(i > len) i = len; - outlet_symbol(x->x_obj.ob_outlet, gensym(str+i)); - freebytes(str, (len+2)*sizeof(char)); + outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_mem+i)); } else outlet_symbol(x->x_obj.ob_outlet, s); |