diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-31 17:06:38 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-31 17:08:30 -0700 |
commit | 18e626dfe83c21822debc6f5a56eaea2b3102220 (patch) | |
tree | bf09bff528d2fefb72bd2349cb05cfa362d7156a /032array.cc | |
parent | 37a173b8a9c09ba96f6f8b75b89ae4e9521d5273 (diff) | |
download | mu-18e626dfe83c21822debc6f5a56eaea2b3102220.tar.gz |
1909 - clean up all null pointers of that ilk
Diffstat (limited to '032array.cc')
-rw-r--r-- | 032array.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/032array.cc b/032array.cc index 5911f1c3..eae33f4c 100644 --- a/032array.cc +++ b/032array.cc @@ -79,16 +79,19 @@ INDEX, Recipe_ordinal["index"] = INDEX; :(before "End Primitive Recipe Implementations") case INDEX: { + products.resize(1); if (SIZE(ingredients) != 2) { raise << current_recipe_name() << ": 'index' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end(); - products.resize(1); break; } reagent base = canonize(current_instruction().ingredients.at(0)); - long long int base_address = base.value; if (base.types.at(0) != Type_ordinal["array"]) { raise << current_recipe_name () << ": 'index' on a non-array " << base.original_string << '\n' << end(); - products.resize(1); + break; + } + long long int base_address = base.value; + if (base_address == 0) { + raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end(); break; } reagent offset = canonize(current_instruction().ingredients.at(1)); @@ -96,7 +99,6 @@ case INDEX: { vector<type_ordinal> element_type = array_element(base.types); if (offset_val.at(0) < 0 || offset_val.at(0) >= Memory[base_address]) { raise << current_recipe_name() << ": invalid index " << offset_val.at(0) << '\n' << end(); - products.resize(1); break; } long long int src = base_address + 1 + offset_val.at(0)*size_of(element_type); @@ -105,7 +107,7 @@ case INDEX: { reagent tmp; tmp.set_value(src); copy(element_type.begin(), element_type.end(), inserter(tmp.types, tmp.types.begin())); - products.push_back(read_memory(tmp)); + products.at(0) = read_memory(tmp); break; } @@ -179,11 +181,15 @@ case INDEX_ADDRESS: { break; } reagent base = canonize(current_instruction().ingredients.at(0)); - long long int base_address = base.value; if (base.types.at(0) != Type_ordinal["array"]) { raise << current_recipe_name () << ": 'index-address' on a non-array " << base.original_string << '\n' << end(); break; } + long long int base_address = base.value; + if (base_address == 0) { + raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end(); + break; + } reagent offset = canonize(current_instruction().ingredients.at(1)); vector<double> offset_val(read_memory(offset)); vector<type_ordinal> element_type = array_element(base.types); @@ -254,6 +260,10 @@ case LENGTH: { raise << "tried to calculate length of non-array " << x.original_string << '\n' << end(); break; } + if (x.value == 0) { + raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end(); + break; + } products.at(0).push_back(Memory[x.value]); break; } |