}
static void
-dump_category(int level, int *indexes, int *n_indexes)
+dump_category(int level, int *indexes, int *n_indexes, int max_indexes)
{
for (int i = 0; i <= level; i++)
fprintf (stdout, " ");
fprintf(stderr, "index not -1 but subcategories\n");
exit(1);
}
+ if (*n_indexes >= max_indexes)
+ {
+ fprintf(stderr, "too many categories (increase max_indexes)\n");
+ exit(1);
+ }
indexes[(*n_indexes)++] = indx;
}
if (n_categories == 0)
fprintf (stdout, "<category-index>%d</category-index>\n", indx);
}
for (int i = 0; i < n_categories; i++)
- dump_category (level + 1, indexes, n_indexes);
+ dump_category (level + 1, indexes, n_indexes, max_indexes);
for (int i = 0; i <= level; i++)
fprintf (stdout, " ");
printf ("</category>\n");
match_u32_assert(indx);
n_categories = get_u32();
- int indexes[1024];
+ int indexes[2048];
int n_indexes = 0;
for (int i = 0; i < n_categories; i++)
- dump_category (0, indexes, &n_indexes);
+ dump_category (0, indexes, &n_indexes, sizeof indexes / sizeof *indexes);
check_permutation(indexes, n_indexes, "categories");
fprintf (stdout, "</dimension>\n");