Skip to content

Commit

Permalink
allow reserved enums to be negative
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsalo authored and copybara-github committed Dec 10, 2022
1 parent 68d1d91 commit 1b0b06f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions upb/reflection/enum_reserved_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ upb_EnumReservedRange* _upb_EnumReservedRanges_New(
google_protobuf_EnumDescriptorProto_EnumReservedRange_start(protos[i]);
const int32_t end =
google_protobuf_EnumDescriptorProto_EnumReservedRange_end(protos[i]);
const int32_t max = kUpb_MaxFieldNumber + 1;

// A full validation would also check that each range is disjoint, and that
// none of the fields overlap with the extension ranges, but we are just
// sanity checking here.

// Note: Not a typo! Unlike extension ranges and message reserved ranges,
// the end value of an enum reserved range is *inclusive*!
if (start < 1 || end < start || end > max) {
if (end < start) {
_upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n",
(int)start, (int)end, upb_EnumDef_FullName(e));
}
Expand Down

0 comments on commit 1b0b06f

Please sign in to comment.