Revision: 9801 http://pure-data.svn.sourceforge.net/pure-data/?rev=9801&view=rev Author: eighthave Date: 2008-05-14 10:49:20 -0700 (Wed, 14 May 2008)
Log Message: ----------- - fixed crasher bug on GNU/Linux and broken help patches on Mac OS X caused by the tilde interpretation code
- switched all char* operations for filenames from using MAXPDSTRING to using the POSIX FILENAME_MAX
These changes are reflected in patches 1963983 and 1961878
Modified Paths: -------------- branches/pd-extended/v0-40/pd/src/d_soundfile.c branches/pd-extended/v0-40/pd/src/g_array.c branches/pd-extended/v0-40/pd/src/g_canvas.c branches/pd-extended/v0-40/pd/src/g_editor.c branches/pd-extended/v0-40/pd/src/m_binbuf.c branches/pd-extended/v0-40/pd/src/m_class.c branches/pd-extended/v0-40/pd/src/m_pd.h branches/pd-extended/v0-40/pd/src/s_file.c branches/pd-extended/v0-40/pd/src/s_loader.c branches/pd-extended/v0-40/pd/src/s_main.c branches/pd-extended/v0-40/pd/src/s_path.c
Modified: branches/pd-extended/v0-40/pd/src/d_soundfile.c =================================================================== --- branches/pd-extended/v0-40/pd/src/d_soundfile.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/d_soundfile.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -404,9 +404,9 @@ int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, long skipframes) { - char buf[OBUFSIZE], *bufptr; + char buf[FILENAME_MAX], *bufptr; int fd; - fd = open_via_path(dirname, filename, "", buf, &bufptr, MAXPDSTRING, 1); + fd = open_via_path(dirname, filename, "", buf, &bufptr, FILENAME_MAX, 1); if (fd < 0) return (-1); else return (open_soundfile_via_fd(fd, headersize, p_bytespersamp, @@ -420,9 +420,9 @@ int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, long skipframes) { - char buf[OBUFSIZE], *bufptr; + char buf[FILENAME_MAX], *bufptr; int fd; - fd = canvas_open(canvas, filename, "", buf, &bufptr, MAXPDSTRING, 1); + fd = canvas_open(canvas, filename, "", buf, &bufptr, FILENAME_MAX, 1); if (fd < 0) return (-1); else return (open_soundfile_via_fd(fd, headersize, p_bytespersamp, @@ -674,15 +674,15 @@ int filetype, int nframes, int bytespersamp, int bigendian, int nchannels, int swap, float samplerate) { - char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; + char filenamebuf[FILENAME_MAX], buf2[FILENAME_MAX]; char headerbuf[WRITEHDRSIZE]; t_wave *wavehdr = (t_wave *)headerbuf; t_nextstep *nexthdr = (t_nextstep *)headerbuf; t_aiff *aiffhdr = (t_aiff *)headerbuf; int fd, headersize = 0;
- strncpy(filenamebuf, filename, MAXPDSTRING-10); - filenamebuf[MAXPDSTRING-10] = 0; + strncpy(filenamebuf, filename, FILENAME_MAX-10); + filenamebuf[FILENAME_MAX-10] = 0;
if (filetype == FORMAT_NEXT) { @@ -748,7 +748,7 @@ headersize = sizeof(t_wave); }
- canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING); + canvas_makefilename(canvas, filenamebuf, buf2, FILENAME_MAX); sys_bashfilename(buf2, buf2); if ((fd = open(buf2, BINCREATE, 0666)) < 0) return (-1);
Modified: branches/pd-extended/v0-40/pd/src/g_array.c =================================================================== --- branches/pd-extended/v0-40/pd/src/g_array.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/g_array.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -1372,7 +1372,7 @@ { int nelem, filedesc, i; FILE *fd; - char buf[MAXPDSTRING], *bufptr; + char buf[FILENAME_MAX], *bufptr; int yonset, elemsize; t_array *array = garray_getarray_floatonly(x, &yonset, &elemsize); if (!array) @@ -1382,7 +1382,7 @@ } nelem = array->a_n; if ((filedesc = canvas_open(glist_getcanvas(x->x_glist), - filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0 + filename->s_name, "", buf, &bufptr, FILENAME_MAX, 0)) < 0 || !(fd = fdopen(filedesc, "r"))) { error("%s: can't open", filename->s_name);
Modified: branches/pd-extended/v0-40/pd/src/g_canvas.c =================================================================== --- branches/pd-extended/v0-40/pd/src/g_canvas.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/g_canvas.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -1581,7 +1581,6 @@ { t_namelist *nl, thislist; int fd = -1; - char listbuf[MAXPDSTRING]; t_canvas *y;
/* first check if "name" is absolute (and if so, try to open) */ @@ -1601,12 +1600,12 @@ dir = (x2 ? canvas_getdir(x2)->s_name : "."); for (nl = y->gl_env->ce_path; nl; nl = nl->nl_next) { - char realname[MAXPDSTRING]; - strncpy(realname, dir, MAXPDSTRING); - realname[MAXPDSTRING-3] = 0; + char realname[FILENAME_MAX]; + strncpy(realname, dir, FILENAME_MAX); + realname[FILENAME_MAX-3] = 0; strcat(realname, "/"); - strncat(realname, nl->nl_string, MAXPDSTRING-strlen(realname)); - realname[MAXPDSTRING-1] = 0; + strncat(realname, nl->nl_string, FILENAME_MAX-strlen(realname)); + realname[FILENAME_MAX-1] = 0; if ((fd = sys_trytoopenone(realname, name, ext, dirresult, nameresult, size, bin)) >= 0) return (fd);
Modified: branches/pd-extended/v0-40/pd/src/g_editor.c =================================================================== --- branches/pd-extended/v0-40/pd/src/g_editor.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/g_editor.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -978,7 +978,7 @@ "open," or "help." */ static void canvas_done_popup(t_canvas *x, float which, float xpos, float ypos) { - char pathbuf[MAXPDSTRING], namebuf[MAXPDSTRING]; + char pathbuf[FILENAME_MAX], namebuf[FILENAME_MAX]; t_gobj *y; for (y = x->gl_list; y; y = y->g_next) { @@ -1010,7 +1010,7 @@ t_atom *av = binbuf_getvec(ob->te_binbuf); if (ac < 1) return; - atom_string(av, namebuf, MAXPDSTRING); + atom_string(av, namebuf, FILENAME_MAX); dir = canvas_getdir((t_canvas *)y)->s_name; } else
Modified: branches/pd-extended/v0-40/pd/src/m_binbuf.c =================================================================== --- branches/pd-extended/v0-40/pd/src/m_binbuf.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/m_binbuf.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -700,7 +700,7 @@
static int binbuf_doopen(char *s, int mode) { - char namebuf[MAXPDSTRING]; + char namebuf[FILENAME_MAX]; #ifdef MSW mode |= O_BINARY; #endif @@ -710,7 +710,7 @@
static FILE *binbuf_dofopen(char *s, char *mode) { - char namebuf[MAXPDSTRING]; + char namebuf[FILENAME_MAX]; sys_bashfilename(s, namebuf); return (fopen(namebuf, mode)); } @@ -721,7 +721,7 @@ int fd; int readret; char *buf; - char namebuf[MAXPDSTRING]; + char namebuf[FILENAME_MAX];
namebuf[0] = 0; if (*dirname) @@ -774,9 +774,9 @@ int crflag) { int filedesc; - char buf[MAXPDSTRING], *bufptr; + char buf[FILENAME_MAX], *bufptr; if ((filedesc = canvas_open(canvas, filename, "", - buf, &bufptr, MAXPDSTRING, 0)) < 0) + buf, &bufptr, FILENAME_MAX, 0)) < 0) { error("%s: can't open", filename); return (1); @@ -792,9 +792,9 @@ int crflag) { int filedesc; - char buf[MAXPDSTRING], *bufptr; + char buf[FILENAME_MAX], *bufptr; if ((filedesc = open_via_path( - dirname, filename, "", buf, &bufptr, MAXPDSTRING, 0)) < 0) + dirname, filename, "", buf, &bufptr, FILENAME_MAX, 0)) < 0) { error("%s: can't open", filename); return (1); @@ -813,7 +813,7 @@ int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag) { FILE *f = 0; - char sbuf[WBUFSIZE], fbuf[MAXPDSTRING], *bp = sbuf, *ep = sbuf + WBUFSIZE; + char sbuf[WBUFSIZE], fbuf[FILENAME_MAX], *bp = sbuf, *ep = sbuf + WBUFSIZE; t_atom *ap; int indx, deleteit = 0; int ncolumn = 0;
Modified: branches/pd-extended/v0-40/pd/src/m_class.c =================================================================== --- branches/pd-extended/v0-40/pd/src/m_class.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/m_class.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -520,7 +520,7 @@
static t_symbol *addfileextent(t_symbol *s) { - char namebuf[MAXPDSTRING], *str = s->s_name; + char namebuf[FILENAME_MAX], *str = s->s_name; int ln = strlen(str); if (!strcmp(str + ln - 3, ".pd")) return (s); strcpy(namebuf, str); @@ -544,7 +544,7 @@ { t_pd *current; int fd; - char dirbuf[MAXPDSTRING], *nameptr; + char dirbuf[FILENAME_MAX], *nameptr; if (tryingalready) return; newest = 0; class_loadsym = s; @@ -558,9 +558,9 @@ class_loadsym = 0; current = s__X.s_thing; if ((fd = canvas_open(canvas_getcurrent(), s->s_name, ".pd", - dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 || + dirbuf, &nameptr, FILENAME_MAX, 0)) >= 0 || (fd = canvas_open(canvas_getcurrent(), s->s_name, ".pat", - dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) + dirbuf, &nameptr, FILENAME_MAX, 0)) >= 0) { close (fd); if (!pd_setloadingabstraction(s))
Modified: branches/pd-extended/v0-40/pd/src/m_pd.h =================================================================== --- branches/pd-extended/v0-40/pd/src/m_pd.h 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/m_pd.h 2008-05-14 17:49:20 UTC (rev 9801) @@ -51,7 +51,7 @@ #include <stddef.h> /* just for size_t -- how lame! */ #endif
-#define MAXPDSTRING 1000 /* use this for anything you want */ +#define MAXPDSTRING 1000 /* must be >= FILENAME_MAX */ #define MAXPDARG 5 /* max number of args we can typecheck today */
/* signed and unsigned integer types the size of a pointer: */
Modified: branches/pd-extended/v0-40/pd/src/s_file.c =================================================================== --- branches/pd-extended/v0-40/pd/src/s_file.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/s_file.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -48,25 +48,25 @@
static void sys_initloadpreferences( void) { - char filenamebuf[MAXPDSTRING], *homedir = getenv("HOME"); + char filenamebuf[FILENAME_MAX], *homedir = getenv("HOME"); int fd, length; - char user_prefs_file[MAXPDSTRING]; // user prefs file - char default_prefs_file[MAXPDSTRING]; // default prefs embedded in the package + char user_prefs_file[FILENAME_MAX]; // user prefs file + char default_prefs_file[FILENAME_MAX]; // default prefs embedded in the package struct stat statbuf;
- snprintf(default_prefs_file, MAXPDSTRING, "%s/default.pdsettings", + snprintf(default_prefs_file, FILENAME_MAX, "%s/default.pdsettings", sys_libdir->s_name); // fprintf(stderr,"default_prefs %s\n",default_prefs_file); if (homedir) - snprintf(user_prefs_file, MAXPDSTRING, "%s/.pdsettings", homedir); + snprintf(user_prefs_file, FILENAME_MAX, "%s/.pdsettings", homedir); if (stat(user_prefs_file, &statbuf) == 0) - strncpy(filenamebuf, user_prefs_file, MAXPDSTRING); + strncpy(filenamebuf, user_prefs_file, FILENAME_MAX); else if (stat(default_prefs_file, &statbuf) == 0) - strncpy(filenamebuf, default_prefs_file, MAXPDSTRING); + strncpy(filenamebuf, default_prefs_file, FILENAME_MAX); else return; - filenamebuf[MAXPDSTRING-1] = 0; + filenamebuf[FILENAME_MAX-1] = 0; if ((fd = open(filenamebuf, 0)) < 0) { if (sys_verbose) @@ -135,17 +135,17 @@
static void sys_initsavepreferences( void) { - char filenamebuf[MAXPDSTRING], errbuf[MAXPDSTRING], + char filenamebuf[FILENAME_MAX], errbuf[FILENAME_MAX], *homedir = getenv("HOME"); FILE *fp;
if (!homedir) return; - snprintf(filenamebuf, MAXPDSTRING, "%s/.pdsettings", homedir); - filenamebuf[MAXPDSTRING-1] = 0; + snprintf(filenamebuf, FILENAME_MAX, "%s/.pdsettings", homedir); + filenamebuf[FILENAME_MAX-1] = 0; if ((sys_prefsavefp = fopen(filenamebuf, "w")) == NULL) { - snprintf(errbuf, MAXPDSTRING, "%s: %s",filenamebuf, strerror(errno)); + snprintf(errbuf, FILENAME_MAX, "%s: %s",filenamebuf, strerror(errno)); pd_error(0, errbuf); } } @@ -235,19 +235,19 @@ { char cmdbuf[256]; int nread = 0, nleft = size; - char default_prefs[MAXPDSTRING]; // default prefs embedded in the package - char embedded_prefs[MAXPDSTRING]; // overrides others for standalone app - char embedded_prefs_file[MAXPDSTRING]; - char user_prefs_file[MAXPDSTRING]; + char default_prefs[FILENAME_MAX]; // default prefs embedded in the package + char embedded_prefs[FILENAME_MAX]; // overrides others for standalone app + char embedded_prefs_file[FILENAME_MAX]; + char user_prefs_file[FILENAME_MAX]; char *homedir = getenv("HOME"); struct stat statbuf; /* the 'defaults' command expects the filename without .plist at the end */ - snprintf(default_prefs, MAXPDSTRING, "%s/../org.puredata.pd.default", + snprintf(default_prefs, FILENAME_MAX, "%s/../org.puredata.pd.default", sys_libdir->s_name); - snprintf(embedded_prefs, MAXPDSTRING, "%s/../org.puredata.pd", + snprintf(embedded_prefs, FILENAME_MAX, "%s/../org.puredata.pd", sys_libdir->s_name); - snprintf(embedded_prefs_file, MAXPDSTRING, "%s.plist", embedded_prefs); - snprintf(user_prefs_file, MAXPDSTRING, + snprintf(embedded_prefs_file, FILENAME_MAX, "%s.plist", embedded_prefs); + snprintf(user_prefs_file, FILENAME_MAX, "%s/Library/Preferences/org.puredata.pd.plist", homedir); if (stat(embedded_prefs_file, &statbuf) == 0) {
Modified: branches/pd-extended/v0-40/pd/src/s_loader.c =================================================================== --- branches/pd-extended/v0-40/pd/src/s_loader.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/s_loader.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -91,7 +91,7 @@
static int sys_do_load_lib(t_canvas *canvas, char *objectname) { - char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], + char symname[MAXPDSTRING], filename[FILENAME_MAX], dirbuf[FILENAME_MAX], *classname, *nameptr, altsymname[MAXPDSTRING]; void *dlobj; t_xxx makeout = NULL; @@ -142,23 +142,23 @@ #endif /* try looking in the path for (objectname).(sys_dllextent) ... */ if ((fd = canvas_open(canvas, objectname, sys_dllextent, - dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + dirbuf, &nameptr, FILENAME_MAX, 1)) >= 0) goto gotone; /* same, with the more generic sys_dllextent2 */ if ((fd = canvas_open(canvas, objectname, sys_dllextent2, - dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + dirbuf, &nameptr, FILENAME_MAX, 1)) >= 0) goto gotone; /* next try (objectname)/(classname).(sys_dllextent) ... */ - strncpy(filename, objectname, MAXPDSTRING); + strncpy(filename, objectname, FILENAME_MAX); filename[MAXPDSTRING-2] = 0; strcat(filename, "/"); - strncat(filename, classname, MAXPDSTRING-strlen(filename)); - filename[MAXPDSTRING-1] = 0; + strncat(filename, classname, FILENAME_MAX-strlen(filename)); + filename[FILENAME_MAX-1] = 0; if ((fd = canvas_open(canvas, filename, sys_dllextent, - dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + dirbuf, &nameptr, FILENAME_MAX, 1)) >= 0) goto gotone; if ((fd = canvas_open(canvas, filename, sys_dllextent2, - dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + dirbuf, &nameptr, FILENAME_MAX, 1)) >= 0) goto gotone; return (0); gotone: @@ -166,11 +166,11 @@ class_set_extern_dir(gensym(dirbuf));
/* rebuild the absolute pathname */ - strncpy(filename, dirbuf, MAXPDSTRING); - filename[MAXPDSTRING-2] = 0; + strncpy(filename, dirbuf, FILENAME_MAX); + filename[FILENAME_MAX-2] = 0; strcat(filename, "/"); - strncat(filename, nameptr, MAXPDSTRING-strlen(filename)); - filename[MAXPDSTRING-1] = 0; + strncat(filename, nameptr, FILENAME_MAX-strlen(filename)); + filename[FILENAME_MAX-1] = 0;
#ifdef DL_OPEN dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
Modified: branches/pd-extended/v0-40/pd/src/s_main.c =================================================================== --- branches/pd-extended/v0-40/pd/src/s_main.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/s_main.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -172,9 +172,9 @@
static void openit(const char *dirname, const char *filename) { - char dirbuf[MAXPDSTRING], *nameptr; + char dirbuf[FILENAME_MAX], *nameptr; int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr, - MAXPDSTRING, 0); + FILENAME_MAX, 0); if (fd) { close (fd);
Modified: branches/pd-extended/v0-40/pd/src/s_path.c =================================================================== --- branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-14 17:47:05 UTC (rev 9800) +++ branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-14 17:49:20 UTC (rev 9801) @@ -225,9 +225,11 @@ char *dirresult, char **nameresult, unsigned int size, int bin) { int fd; + char buf[FILENAME_MAX]; if (strlen(dir) + strlen(name) + strlen(ext) + 4 > size) return (-1); - sys_expandpath(dir, dirresult); + sys_expandpath(dir, buf); + strcpy(dirresult, buf); if (*dirresult && dirresult[strlen(dirresult)-1] != '/') strcat(dirresult, "/"); strcat(dirresult, name); @@ -285,10 +287,10 @@ #endif ) { - char dirbuf[MAXPDSTRING]; + char dirbuf[FILENAME_MAX]; int dirlen = (strrchr(name, '/') - name); - if (dirlen > MAXPDSTRING-1) - dirlen = MAXPDSTRING-1; + if (dirlen > FILENAME_MAX-1) + dirlen = FILENAME_MAX-1; strncpy(dirbuf, name, dirlen); dirbuf[dirlen] = 0; *fdp = sys_trytoopenone(dirbuf, name+(dirlen+1), ext, @@ -355,32 +357,32 @@ search attempts. */ void open_via_helppath(const char *name, const char *dir) { - char realname[MAXPDSTRING], dirbuf[MAXPDSTRING], *basename; + char realname[FILENAME_MAX], dirbuf[FILENAME_MAX], *basename; /* make up a silly "dir" if none is supplied */ const char *usedir = (*dir ? dir : "./"); int fd;
/* 1. "objectname-help.pd" */ - strncpy(realname, name, MAXPDSTRING-10); - realname[MAXPDSTRING-10] = 0; + strncpy(realname, name, FILENAME_MAX-10); + realname[FILENAME_MAX-10] = 0; if (strlen(realname) > 3 && !strcmp(realname+strlen(realname)-3, ".pd")) realname[strlen(realname)-3] = 0; strcat(realname, "-help.pd"); if ((fd = do_open_via_path(dir, realname, "", dirbuf, &basename, - MAXPDSTRING, 0, sys_helppath)) >= 0) + FILENAME_MAX, 0, sys_helppath)) >= 0) goto gotone;
/* 2. "help-objectname.pd" */ strcpy(realname, "help-"); - strncat(realname, name, MAXPDSTRING-10); - realname[MAXPDSTRING-1] = 0; + strncat(realname, name, FILENAME_MAX-10); + realname[FILENAME_MAX-1] = 0; if ((fd = do_open_via_path(dir, realname, "", dirbuf, &basename, - MAXPDSTRING, 0, sys_helppath)) >= 0) + FILENAME_MAX, 0, sys_helppath)) >= 0) goto gotone;
/* 3. "objectname.pd" */ if ((fd = do_open_via_path(dir, name, "", dirbuf, &basename, - MAXPDSTRING, 0, sys_helppath)) >= 0) + FILENAME_MAX, 0, sys_helppath)) >= 0) goto gotone; post("sorry, couldn't find help patch for "%s"", name); return; @@ -408,7 +410,7 @@ int rcargc; char* rcargv[NUMARGS]; char* buffer; - char fname[MAXPDSTRING], buf[1001], *home = getenv("HOME"); + char fname[FILENAME_MAX], buf[1001], *home = getenv("HOME"); int retval = 1; /* that's what we will return at the end; for now, let's think it'll be an error */
/* initialize rc-arg-array so we can safely clean up at the end */ @@ -420,7 +422,7 @@
*fname = '\0';
- strncat(fname, home? home : ".", MAXPDSTRING-10); + strncat(fname, home? home : ".", FILENAME_MAX-10); strcat(fname, "/");
strcat(fname, STARTUPNAME);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.