Update of /cvsroot/pure-data/externals/zexy/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29320
Modified Files: fwriteln.c Log Message: corrected the segmentation fault error in fwriteln. (string length was too short by 1 byte)
Index: fwriteln.c =================================================================== RCS file: /cvsroot/pure-data/externals/zexy/src/fwriteln.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** fwriteln.c 29 Aug 2007 14:36:17 -0000 1.7 --- fwriteln.c 23 Sep 2007 10:54:56 -0000 1.8 *************** *** 56,71 **** x->x_file=0; if(x->x_filename) ! freebytes(x->x_filename, sizeof(char)*MAXPDSTRING); x->x_filename=0; if(x->x_textbuf) ! freebytes(x->x_textbuf, sizeof(char)*MAXPDSTRING); x->x_textbuf=0; }
static void fwriteln_open (t_fwriteln *x, t_symbol *s, t_symbol*type) { ! char filename[MAXPDSTRING]; ! sys_bashfilename (s->s_name, filename); ! filename[MAXPDSTRING-1]=0; fwriteln_close (x);
--- 56,81 ---- x->x_file=0; if(x->x_filename) ! free(x->x_filename); x->x_filename=0; if(x->x_textbuf) ! freebytes(x->x_textbuf, MAXPDSTRING + 1); x->x_textbuf=0; }
+ static void string_copy(const char* const from, char** to) + { + if (*to = malloc(strlen(from) + 1)) { + strcpy(*to, from); + } + } + static void fwriteln_open (t_fwriteln *x, t_symbol *s, t_symbol*type) { ! char* filename; ! ! string_copy(s->s_name, &filename); ! ! sys_bashfilename (filename, filename); ! fwriteln_close (x);
*************** *** 82,90 **** if (!(x->x_file=fopen(filename, "w"))) { pd_error(x, "failed to open %128s",filename); return; } ! x->x_filename=(char*)getbytes(sizeof(char)*strlen(filename)); ! strcpy(x->x_filename,filename); ! x->x_textbuf = (char *) getbytes (MAXPDSTRING * sizeof(char)); }
--- 92,101 ---- if (!(x->x_file=fopen(filename, "w"))) { pd_error(x, "failed to open %128s",filename); + free(filename); return; } ! string_copy(filename, &x->x_filename); ! free(filename); ! x->x_textbuf = (char *) getbytes (MAXPDSTRING + 1); }