From: Ben Pfaff Date: Tue, 28 Jul 2015 02:43:02 +0000 (-0700) Subject: dump: Properly handle more than 1024 categories. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f568543c2d08f0bc57b8dbf2d21da9577cc5c5e;p=pspp dump: Properly handle more than 1024 categories. --- diff --git a/dump.c b/dump.c index 45ae0d8653..aeb26086b0 100644 --- a/dump.c +++ b/dump.c @@ -548,7 +548,7 @@ check_permutation(int *a, int n, const char *name) } 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, " "); @@ -579,6 +579,11 @@ dump_category(int level, int *indexes, int *n_indexes) 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) @@ -588,7 +593,7 @@ dump_category(int level, int *indexes, int *n_indexes) fprintf (stdout, "%d\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 ("\n"); @@ -617,10 +622,10 @@ dump_dim(int indx) 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, "\n");