Id
dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create)
{
- Id did, d, ds, *dirtraverse;
+ Id did, d, ds;
+ if (comp <= 0)
+ return 0;
if (!dp->ndirs)
{
if (!create)
dirpool_make_dirtraverse(dp);
/* check all entries with this parent if we
* already have this component */
- dirtraverse = dp->dirtraverse;
- ds = dirtraverse[parent];
+ ds = dp->dirtraverse[parent];
while (ds)
{
/* ds: first component in this block
dirmap[n++] = sib;
}
+ /* check if our block has some content */
+ if (parent == n)
+ return n - 1; /* nope, drop parent id again */
+
/* now go through all the siblings we just added and
* do recursive calls on them */
lastn = n;