Index: s_path.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_path.c,v retrieving revision 1.11 diff -u -u -r1.11 s_path.c --- s_path.c 8 Sep 2006 23:45:31 -0000 1.11 +++ s_path.c 17 Dec 2007 14:54:32 -0000 @@ -64,21 +64,29 @@ /******************* Utility functions used below ******************/ -/* copy until delimiter and return position after delimiter in string */ -/* if it was the last substring, return NULL */ +/*! + * \brief copy until delimiter + * + * \arg to destination buffer + * \arg to_len destination buffer length + * \arg from source buffer + * \arg delim string delimiter to stop copying on + * + * \return position after delimiter in string. If it was the last + * substring, return NULL. + */ +static const char *strtokcpy(char *to, size_t to_len, const char *from, char delim) +{ + unsigned int i = 0; + + for (; i < (to_len - 1) && from[i] && from[i] != delim; i++) + to[i] = from[i]; + to[i] = '\0'; -static const char* strtokcpy(char *to, const char *from, int delim) -{ - int size = 0; - - while (from[size] != (char)delim && from[size] != '\0') - size++; + if (i && from[i] != '\0') + return from + i + 1; - strncpy(to,from,size); - to[size] = '\0'; - if (from[size] == '\0') return NULL; - if (size) return from+size+1; - else return NULL; + return NULL; } /* add a single item to a namelist. If "allowdup" is true, duplicates @@ -126,7 +134,7 @@ npos = s; do { - npos = strtokcpy(temp, npos, SEPARATOR); + npos = strtokcpy(temp, sizeof(temp), npos, SEPARATOR); if (! *temp) continue; nl = namelist_append(nl, temp, 0); }