Update of /cvsroot/pure-data/externals/iemlib/src/iemlib2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11217/iemlib/src/iemlib2
Modified Files: mergefilename.c splitfilename.c stripfilename.c Log Message: fixed this bug with MAXPDSTRING memory allocation
Index: mergefilename.c =================================================================== RCS file: /cvsroot/pure-data/externals/iemlib/src/iemlib2/mergefilename.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** mergefilename.c 9 Nov 2006 18:48:30 -0000 1.8 --- mergefilename.c 21 Nov 2006 14:43:21 -0000 1.9 *************** *** 21,25 **** t_object x_obj; char x_sep[2]; ! char x_mem[MAXPDSTRING]; /* miller WHY ???? */ } t_mergefilename;
--- 21,25 ---- t_object x_obj; char x_sep[2]; ! char x_mem[MAXPDSTRING]; } t_mergefilename;
Index: stripfilename.c =================================================================== RCS file: /cvsroot/pure-data/externals/iemlib/src/iemlib2/stripfilename.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** stripfilename.c 7 Nov 2006 17:11:40 -0000 1.5 --- stripfilename.c 21 Nov 2006 14:43:21 -0000 1.6 *************** *** 18,49 **** t_object x_obj; int x_nr_char; } t_stripfilename;
static void stripfilename_symbol(t_stripfilename *x, t_symbol *s) { ! if(x->x_nr_char < 0) { 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(i < 0) i = 0; ! str[i] = 0; ! outlet_symbol(x->x_obj.ob_outlet, gensym(str)); ! freebytes(str, (len+2)*sizeof(char)); } ! else if(x->x_nr_char > 0) { 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(i > len) i = len; ! outlet_symbol(x->x_obj.ob_outlet, gensym(str+i)); ! freebytes(str, (len+2)*sizeof(char)); } else --- 18,52 ---- 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)/* cuts the string from the back */ { int len = strlen(s->s_name); int i=len + x->x_nr_char; ! ! 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; ! x->x_mem[i] = 0; ! outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_mem)); } ! else if(x->x_nr_char > 0)/* starts the string at this new offset */ { int len = strlen(s->s_name); int i=x->x_nr_char; ! ! 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(x->x_mem+i)); } else
Index: splitfilename.c =================================================================== RCS file: /cvsroot/pure-data/externals/iemlib/src/iemlib2/splitfilename.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** splitfilename.c 7 Nov 2006 17:11:40 -0000 1.9 --- splitfilename.c 21 Nov 2006 14:43:21 -0000 1.10 *************** *** 21,25 **** t_object x_obj; char x_sep[2]; ! char *x_mem; t_int x_size; t_outlet *x_outpath; --- 21,25 ---- t_object x_obj; char x_sep[2]; ! char x_mem[MAXPDSTRING]; t_int x_size; t_outlet *x_outpath; *************** *** 78,88 **** { 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); 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)) --- 78,87 ---- { char *sep_ptr=x->x_mem; ! ! 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)) *************** *** 107,115 **** }
- 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) { --- 106,109 ---- *************** *** 122,127 **** 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); --- 116,119 ----