From 42e028972517891ef2f5ba9855cec9cf1f8764e0 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Lopes Date: Mon, 8 Oct 2007 16:07:10 +0000 Subject: [PATCH] Fix bug in mangle_all. --- libisofs/trunk/libisofs/ecma119_tree.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libisofs/trunk/libisofs/ecma119_tree.c b/libisofs/trunk/libisofs/ecma119_tree.c index dc140fbc..60441421 100644 --- a/libisofs/trunk/libisofs/ecma119_tree.c +++ b/libisofs/trunk/libisofs/ecma119_tree.c @@ -583,8 +583,10 @@ mangle_all(struct ecma119_tree_node *dir) struct ecma119_dir_info d = dir->info.dir; size_t n_change; int changed; + size_t digits; assert(dir->type == ECMA119_DIR); + digits = 1; do { changed = 0; for (i=0; i < d.nchildren; i++) { @@ -598,7 +600,7 @@ mangle_all(struct ecma119_tree_node *dir) /* mangle the names */ changed = 1; - n_change = j / 10 + 1; + n_change = j / 10 + digits; for (k=0; k < j; k++) { mangle_name(&(d.children[i+k]->iso_name), n_change, @@ -612,6 +614,12 @@ mangle_all(struct ecma119_tree_node *dir) /* skip ahead by the number of mangled names */ i += j - 1; } + if (changed) { + /* we need to reorder */ + qsort(dir->info.dir.children, dir->info.dir.nchildren, + sizeof(void*), cmp_node); + } + digits++; } while (changed); for (i=0; i < d.nchildren; i++) {