Ensure we don't subtract with underflow getting enum names (#5246)

* Ensure we don't subtract with underflow getting enum names

* Yep - forgot to run this
This commit is contained in:
Matt Mastracci
2019-04-05 13:30:58 -06:00
committed by Wouter van Oortmerssen
parent 249f3b3714
commit c329d6fa90
3 changed files with 13 additions and 13 deletions

View File

@@ -698,14 +698,14 @@ class RustGenerator : public BaseGenerator {
code_ += "pub fn enum_name_{{ENUM_NAME_SNAKE}}(e: {{ENUM_NAME}}) -> "
"&'static str {";
code_ += " let index: usize = e as usize\\";
code_ += " let index = e as {{BASE_TYPE}}\\";
if (enum_def.vals.vec.front()->value) {
auto vals = GetEnumValUse(enum_def, *enum_def.vals.vec.front());
code_ += " - " + vals + " as usize\\";
code_ += " - " + vals + " as {{BASE_TYPE}}\\";
}
code_ += ";";
code_ += " ENUM_NAMES_{{ENUM_NAME_CAPS}}[index]";
code_ += " ENUM_NAMES_{{ENUM_NAME_CAPS}}[index as usize]";
code_ += "}";
code_ += "";
}