dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
646 stars 182 forks source link

The enum value is out of range. #176

Closed yl0727 closed 3 years ago

yl0727 commented 3 years ago

Blocking of enumeration value out-of-bounds: When assigning values to enumeration members, flatcc only intercepts the members that are actively assigned but ignores the members that follow the enumeration. For example, if you assign 255 to the first member of the enum of the uint8 type, the second member is 256, which exceeds the maximum value 255. image

mikkelfj commented 3 years ago

Ah I see, thanks for reporting.

mikkelfj commented 3 years ago

@yl0727 Could you please this branch https://github.com/dvidelabs/flatcc/tree/enumrange

I have only tested that it doesn't break anything, not that it fixes your issue.

I think I made small mistake - the source comment suggests the type coercion call should also work for auto-increment, but it was placed inside a branch that only executed for assigned values. So basically I just moved a bracket:

https://github.com/dvidelabs/flatcc/commit/f4ec267ae043dd35cb3965d7b1232a6eee034799

mikkelfj commented 3 years ago

Merging enumrange branch to master and closing this issue.