chiark / gitweb /
remove debugging output
[chiark-utils.git] / cprogs / summer.c
index 887409db55bb0d3ed43d8c675a65b3b61332d3bd..19c806987c18bf4d190382927acced0aa21c1e02 100644 (file)
@@ -287,24 +287,29 @@ static int recurse_compar(const void *av, const void *bv) {
   return strcmp((*a)->d_name, (*b)->d_name);
 }
 
-static void recurse(const char *path) {
+static void recurse(const char *path_or_buf) {
   static char *buf;
   static int buf_allocd;
   
   struct dirent **namelist, *const *de;
   char *subpathp;
+  const char *path_or_0= path_or_buf==buf ? 0 : path_or_buf;
   int nentries, pathl, esave, buf_want, i;
 
-  pathl= strlen(path);
+  pathl= strlen(path_or_buf);
   recurse_maxlen= 2;
-  nentries= scandir(path, &namelist, recurse_filter, recurse_compar);
+  nentries= scandir(path_or_buf, &namelist, recurse_filter, recurse_compar);
   esave= errno;
+  
   buf_want= pathl+1+recurse_maxlen+1;
   if (buf_want > buf_allocd) {
     buf= mrealloc(buf, buf_want);
     buf_allocd= buf_want;
   }
-  strcpy(buf,path);
+  /* NOTE that path_or_buf is invalid after this point because
+   * it might have been realloc'd ! */
+  if (path_or_0) strcpy(buf,path_or_0);
+
   buf[pathl]= '/';
   subpathp= buf+pathl+1;
   if (nentries < 0) {