diff options
author | Matt Mastracci <matthew@mastracci.com> | 2019-04-05 13:30:58 -0600 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-04-05 12:30:58 -0700 |
commit | c329d6fa9069890c7fbd62d7bffdbe5c776ed620 (patch) | |
tree | 8451bfbfb7c74c1d83bda8e9a35462b716de7250 /src/idl_gen_rust.cpp | |
parent | 249f3b37149daabbf4954dc8d615e97238b692b9 (diff) | |
download | flatbuffers-c329d6fa9069890c7fbd62d7bffdbe5c776ed620.tar.gz flatbuffers-c329d6fa9069890c7fbd62d7bffdbe5c776ed620.tar.bz2 flatbuffers-c329d6fa9069890c7fbd62d7bffdbe5c776ed620.zip |
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
Diffstat (limited to 'src/idl_gen_rust.cpp')
-rw-r--r-- | src/idl_gen_rust.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index e8ecbbc4..1b8ff116 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -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_ += ""; } |