add allowed ranges to error messages

pull/10555/head
Josh Humphries 2 years ago
parent 2270d3f93c
commit 87f24e4759
  1. 18
      src/google/protobuf/descriptor.cc
  2. 16
      src/google/protobuf/descriptor_unittest.cc

@ -7683,7 +7683,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() > if (uninterpreted_option_->positive_int_value() >
static_cast<uint64_t>(std::numeric_limits<int32_t>::max())) { static_cast<uint64_t>(std::numeric_limits<int32_t>::max())) {
return AddValueError("Value out of range for int32 option \"" + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} else { } else {
SetInt32(option_field->number(), SetInt32(option_field->number(),
@ -7693,7 +7693,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
} else if (uninterpreted_option_->has_negative_int_value()) { } else if (uninterpreted_option_->has_negative_int_value()) {
if (uninterpreted_option_->negative_int_value() < if (uninterpreted_option_->negative_int_value() <
static_cast<int64_t>(std::numeric_limits<int32_t>::min())) { static_cast<int64_t>(std::numeric_limits<int32_t>::min())) {
return AddValueError("Value out of range for int32 option \"" + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} else { } else {
SetInt32(option_field->number(), SetInt32(option_field->number(),
@ -7701,7 +7701,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
option_field->type(), unknown_fields); option_field->type(), unknown_fields);
} }
} else { } else {
return AddValueError("Value must be integer for int32 option \"" + return AddValueError("Value must be integer, from -2,147,483,648 to 2,147,483,647, for int32 option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} }
break; break;
@ -7710,7 +7710,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() > if (uninterpreted_option_->positive_int_value() >
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) { static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
return AddValueError("Value out of range for int64 option \"" + return AddValueError("Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} else { } else {
SetInt64(option_field->number(), SetInt64(option_field->number(),
@ -7722,7 +7722,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
uninterpreted_option_->negative_int_value(), uninterpreted_option_->negative_int_value(),
option_field->type(), unknown_fields); option_field->type(), unknown_fields);
} else { } else {
return AddValueError("Value must be integer for int64 option \"" + return AddValueError("Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} }
break; break;
@ -7731,7 +7731,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() > if (uninterpreted_option_->positive_int_value() >
std::numeric_limits<uint32_t>::max()) { std::numeric_limits<uint32_t>::max()) {
return AddValueError("Value out of range for uint32 option \"" + return AddValueError("Value out of range, 0 to 4,294,967,295, for uint32 option \"" +
option_field->name() + "\"."); option_field->name() + "\".");
} else { } else {
SetUInt32(option_field->number(), SetUInt32(option_field->number(),
@ -7740,8 +7740,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
} }
} else { } else {
return AddValueError( return AddValueError(
"Value must be non-negative integer for uint32 " "Value must be integer, from 0 to 4,294,967,295, for uint32 option \"" +
"option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} }
break; break;
@ -7753,8 +7752,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
option_field->type(), unknown_fields); option_field->type(), unknown_fields);
} else { } else {
return AddValueError( return AddValueError(
"Value must be non-negative integer for uint64 " "Value must be integer, from 0 to 18,446,744,073,709,551,615, for uint64 option \"" +
"option \"" +
option_field->full_name() + "\"."); option_field->full_name() + "\".");
} }
break; break;

@ -5557,7 +5557,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfPositiveRange) {
" positive_int_value: 0x80000000 } " " positive_int_value: 0x80000000 } "
"}", "}",
"foo.proto: foo.proto: OPTION_VALUE: Value out of range " "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, "
"for int32 option \"foo\".\n"); "for int32 option \"foo\".\n");
} }
@ -5574,7 +5574,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfNegativeRange) {
" negative_int_value: -0x80000001 } " " negative_int_value: -0x80000001 } "
"}", "}",
"foo.proto: foo.proto: OPTION_VALUE: Value out of range " "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, "
"for int32 option \"foo\".\n"); "for int32 option \"foo\".\n");
} }
@ -5590,7 +5590,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueIsNotPositiveInt) {
" is_extension: true } " " is_extension: true } "
" string_value: \"5\" } }", " string_value: \"5\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be integer " "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2,147,483,648 to 2,147,483,647, "
"for int32 option \"foo\".\n"); "for int32 option \"foo\".\n");
} }
@ -5608,7 +5608,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueOutOfRange) {
"} " "} "
"}", "}",
"foo.proto: foo.proto: OPTION_VALUE: Value out of range " "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, "
"for int64 option \"foo\".\n"); "for int64 option \"foo\".\n");
} }
@ -5624,7 +5624,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueIsNotPositiveInt) {
" is_extension: true } " " is_extension: true } "
" identifier_value: \"5\" } }", " identifier_value: \"5\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be integer " "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, "
"for int64 option \"foo\".\n"); "for int64 option \"foo\".\n");
} }
@ -5640,7 +5640,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueOutOfRange) {
" is_extension: true } " " is_extension: true } "
" positive_int_value: 0x100000000 } }", " positive_int_value: 0x100000000 } }",
"foo.proto: foo.proto: OPTION_VALUE: Value out of range " "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4,294,967,295, "
"for uint32 option \"foo\".\n"); "for uint32 option \"foo\".\n");
} }
@ -5656,7 +5656,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueIsNotPositiveInt) {
" is_extension: true } " " is_extension: true } "
" double_value: -5.6 } }", " double_value: -5.6 } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4,294,967,295, "
"for uint32 option \"foo\".\n"); "for uint32 option \"foo\".\n");
} }
@ -5672,7 +5672,7 @@ TEST_F(ValidationErrorTest, UInt64OptionValueIsNotPositiveInt) {
" is_extension: true } " " is_extension: true } "
" negative_int_value: -5 } }", " negative_int_value: -5 } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18,446,744,073,709,551,615, "
"for uint64 option \"foo\".\n"); "for uint64 option \"foo\".\n");
} }

Loading…
Cancel
Save