return tmp[on - 1];
}
+#define OVERRUN 99
+
struct t_tree {
struct t_tree *left, *right;
- char name; /* Not just 1 char - space for whole name */
+ char name[OVERRUN+1]; // [HGM] hack below caused crashing on some compilers
+// char name; /* Not just 1 char - space for whole name */
}; /* is allocated. Maybe a little cheesy? */
struct t_dirs {
struct t_dirs *left, *right;
time_t mtime; /* dir's modification time */
struct t_tree *files;
- char name; /* ditto */
+ char name[OVERRUN+1]; // [HGM] ditto
+// char name; /* ditto */
};
static char **t_buffer = NULL; /* pointer to next space in return buffer */
t = &(*t)->right;
}
}
- *t = malloc(sizeof(struct t_tree) + strlen(dp->d_name));
+ *t = malloc(sizeof(struct t_tree) - OVERRUN + strlen(dp->d_name));
(*t)->right = (*t)->left = NULL;
strcpy(&(*t)->name, dp->d_name);
}
i = &(*i)->right;
}
if (!*i) { /* if dir isn't in dir tree, add him */
- *i = malloc(sizeof(struct t_dirs) + strlen(dir));
+ *i = malloc(sizeof(struct t_dirs) - OVERRUN + strlen(dir)); // [HGM] allocate just enough, even though struct promoised more
(*i)->left = (*i)->right = NULL;
(*i)->files = NULL;
strcpy(&(*i)->name, dir);