fix: NetworkBehaviour crash if ignoring a non-last struct field (#1554)

Macro was using field_n (field index including ignored fields) for calculations instad of
enum_n (field index excluding ignored fields). When calculating te nesting the calculation
was made between the number of non-ignored fields and a field_n that lead to and overflow.

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
Arjan Topolovec
2020-04-28 11:38:25 +02:00
committed by GitHub
parent bdbab32392
commit 3d4ae5da4b
2 changed files with 29 additions and 2 deletions

View File

@ -288,7 +288,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
quote!{ ev }
};
for _ in 0 .. data_struct.fields.iter().filter(|f| !is_ignored(f)).count() - 1 - field_n {
for _ in 0 .. data_struct.fields.iter().filter(|f| !is_ignored(f)).count() - 1 - enum_n {
elem = quote!{ #either_ident::First(#elem) };
}
@ -378,7 +378,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
} else {
quote!{ event }
};
for _ in 0 .. data_struct.fields.iter().filter(|f| !is_ignored(f)).count() - 1 - field_n {
for _ in 0 .. data_struct.fields.iter().filter(|f| !is_ignored(f)).count() - 1 - enum_n {
wrapped_event = quote!{ #either_ident::First(#wrapped_event) };
}