Mercurial > hg > octave-lyh
diff src/symtab.cc @ 10304:2ceae0b40515
fix builtin_type for permutation matrices, avoid segfaults with invalid values in get_dispatch_type
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 10 Feb 2010 22:12:36 +0100 |
parents | cd96d29c5efa |
children | 7b5e8527441e |
line wrap: on
line diff
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -452,9 +452,10 @@ // to btyp_num_types (static constant). Only the leftmost dimension can be // variable in C/C++. Typedefs are boring. -static builtin_type_t (*build_sup_table (void))[btyp_num_types] +// For safety, we include btyp_unknown in the table +static builtin_type_t (*build_sup_table (void))[btyp_num_types + 1] { - static builtin_type_t sup_table[btyp_num_types][btyp_num_types]; + static builtin_type_t sup_table[btyp_num_types + 1][btyp_num_types + 1]; for (int i = 0; i < btyp_num_types; i++) for (int j = 0; j < btyp_num_types; j++) { @@ -472,6 +473,12 @@ sup_table[i][j] = use_j ? jtyp : ityp; } + for (int i = 0; i <= btyp_num_types; i++) + { + sup_table[btyp_unknown][i] = btyp_unknown; + sup_table[i][btyp_unknown] = btyp_unknown; + } + return sup_table; } @@ -479,7 +486,7 @@ get_dispatch_type (const octave_value_list& args, bool& builtin_class) { - static builtin_type_t (*sup_table)[btyp_num_types] = build_sup_table (); + static builtin_type_t (*sup_table)[btyp_num_types+1] = build_sup_table (); std::string dispatch_type; int n = args.length (); @@ -530,7 +537,13 @@ if (btyp != btyp_unknown) dispatch_type = btyp_class_name[btyp]; else - builtin_class = false; + { + // Basically, this should never happen if all values are defined. + // If not, that's an internal inconsistency. + builtin_class = false; + error ("internal error: undefined or invalid value in argument list"); + } + } }