[PD] splitfilename bug?

Johannes Burström johannes at ljud.org
Sat Jul 2 15:30:15 CEST 2005


Hi

IOhannes m zmoelnig wrote:
> could you try to replace splitfilename.c with the attached file and
> recompile iemlib2 and look whether this fixes the crash ?
 >
 > i have also checked my change into the CVS but don't know whether you
 > have access.

Yes, i do. and i used the updated source from there, but unfortunately 
it doesn't fix the crash. The "free(): invalid pointer 0x8215550!" 
message doesn't come up anymore upon when it segfaults, however. And the 
backtrace is kind of different (don't have a clue about what it means, 
though...)

(gdb) bt
#0  0x401ee52d in mallopt () from /lib/libc.so.6
#1  0x401edfcc in mallopt () from /lib/libc.so.6
#2  0x401ed763 in calloc () from /lib/libc.so.6
#3  0x080a2a75 in getbytes (nbytes=2053202479) at m_memory.c:24
#4  0x080a2bc4 in binbuf_text (x=0x821e5a0,
     text=0xbfffd630 ".x821f758 key 0 105 0 ; 132.0 1 ;3x323+0+0 ; 
\177\006",
         size=23) at m_binbuf.c:63
#5  0x080ad955 in socketreceiver_doread (x=0x821e5c0) at s_inter.c:420
#6  0x080abaa8 in socketreceiver_read (x=0x821e5c0, fd=402) at s_inter.c:523
#7  0x080ad71f in sys_domicrosleep (microsec=2053202479, pollem=1)
	    at s_inter.c:177
#8  0x080acdf8 in sys_microsleep (microsec=2053202479) at s_inter.c:196
#9  0x080a855f in m_scheduler () at m_sched.c:487
#10 0x080b2a5b in main (argc=2053202479, argv=0x7a61622f) at s_entry.c:27

hope this makes any sense...
johannes


> 
> 
> fmg.asdr.
> IOhanens
> 
> 
> ------------------------------------------------------------------------
> 
> /* For information on usage and redistribution, and for a DISCLAIMER OF ALL
> * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
> 
> iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
> 
> #ifdef NT
> #pragma warning( disable : 4244 )
> #pragma warning( disable : 4305 )
> #endif
> 
> #include "m_pd.h"
> #include "iemlib.h"
> #include <stdlib.h>
> #include <string.h>
> #include <stdio.h>
> 
> /* ----------------------- splitfilename -------------------------- */
> /* -- splits a symbol into 2 parts (path + file) at the position -- */
> /* -- of the first separator-character beginnig from the right ---- */
> /* ---------- eliminating the separator-character ----------------- */
> 
> static t_class *splitfilename_class;
> 
> typedef struct _splitfilename
> {
> 	t_object x_obj;
> 	char     x_sep[2];
> 	void     *x_outpath;
> 	void     *x_outfile;
> } t_splitfilename;
> 
> static void splitfilename_separator(t_splitfilename *x, t_symbol *s, int ac, t_atom *av)
> {
> 	if(ac > 0)
> 	{
> 		if(IS_A_SYMBOL(av, 0))
> 		{
> 			if(strlen(av->a_w.w_symbol->s_name) == 1)
> 				x->x_sep[0] = av->a_w.w_symbol->s_name[0];
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "backslash"))
> 				x->x_sep[0] = '\\';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "slash"))
> 				x->x_sep[0] = '/';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "blank"))
> 				x->x_sep[0] = ' ';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "space"))
> 				x->x_sep[0] = ' ';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "dollar"))
> 				x->x_sep[0] = '$';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "comma"))
> 				x->x_sep[0] = ',';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "semi"))
> 				x->x_sep[0] = ';';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "leftbrace"))
> 				x->x_sep[0] = '{';
> 			else if(!strcmp(av->a_w.w_symbol->s_name, "rightbrace"))
> 				x->x_sep[0] = '}';
> 			else
> 				x->x_sep[0] = '/';
> 		}
> 		else if(IS_A_FLOAT(av, 0))
> 		{
> 			int i;
> 			float f=fabs(av->a_w.w_float);
> 			
> 			while(f >= 10.0)
> 				f *= 0.1;
> 			i = (int)f;
> 			x->x_sep[0] = (char)i + '0';
> 		}
> 	}
> 	else
> 		x->x_sep[0] = 0;
> }
> 
> static void splitfilename_symbol(t_splitfilename *x, t_symbol *s)
> {
> 	int len = strlen(s->s_name);
> 	
> 	if(len)
> 	{
> 		if(x->x_sep[0] != 0)
> 		{
> 			char *str_path = (char *)getbytes(len*sizeof(char));
> 			char *str_file = (char *)getbytes(len*sizeof(char));
> 			char *cpp, *cpf;
> 			
> 			strcpy(str_path, s->s_name);
> 			strcpy(str_file, s->s_name);
> 			cpp = strrchr(str_path, x->x_sep[0]);
> 			cpf = strrchr(str_file, x->x_sep[0]);
> 			if(!cpp) /* JMZ: 20050701 */
> 			{
> 				outlet_symbol(x->x_outfile, gensym(str_file));
> 				outlet_symbol(x->x_outpath, &s_);			  
> 			} 
> 			else if (!cpf) /* JMZ: 20050701 */
> 			{
> 				outlet_symbol(x->x_outfile, &s_);
> 				outlet_symbol(x->x_outpath, gensym(str_path));
> 			}
> 			else if((cpp - str_path) < 0) /* JMZ:removed typecast (char*) to (int); this is not portable */
> 			  {
> 				outlet_symbol(x->x_outfile, gensym(str_file));
> 				outlet_symbol(x->x_outpath, &s_);
> 			  }
> 			else if((cpp - str_path) >= len) /* JMZ: removed typecast (char*) to (int) */
> 			    {
> 				outlet_symbol(x->x_outfile, &s_);
> 				outlet_symbol(x->x_outpath, gensym(str_path));
> 			  }
> 			  else
> 			  {
> 				*cpp = 0;
> 				cpf++;
> 				outlet_symbol(x->x_outfile, gensym(cpf));
> 				outlet_symbol(x->x_outpath, gensym(str_path));
> 			  }
> 			freebytes(str_file, len*sizeof(char));
> 			freebytes(str_path, len*sizeof(char));
> 		}
> 		else
> 		{
> 			outlet_symbol(x->x_outfile, &s_);
> 			outlet_symbol(x->x_outpath, s);
> 		}
> 	}
> }
> 
> static void *splitfilename_new(t_symbol *s, int ac, t_atom *av)
> {
> 	t_splitfilename *x = (t_splitfilename *)pd_new(splitfilename_class);
> 	
> 	x->x_sep[0] = 0;
> 	x->x_sep[1] = 0;
> 	if(ac == 0)
> 		x->x_sep[0] = '/';
> 	else
> 		splitfilename_separator(x, s, ac, av);
> 	x->x_outpath = outlet_new(&x->x_obj, &s_symbol);
> 	x->x_outfile = outlet_new(&x->x_obj, &s_symbol);
> 	return (x);
> }
> 
> void splitfilename_setup(void)
> {
> 	splitfilename_class = class_new(gensym("splitfilename"), (t_newmethod)splitfilename_new,
> 		0, sizeof(t_splitfilename), 0, A_GIMME, 0);
> 	class_addsymbol(splitfilename_class, splitfilename_symbol);
> 	class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("separator"), A_GIMME, 0);
> 	class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("sep"), A_GIMME, 0);
> 	class_sethelpsymbol(splitfilename_class, gensym("iemhelp/help-splitfilename"));
> }




More information about the Pd-list mailing list