@@ -765,16 +765,42 @@ void configt::set_arch(const irep_idt &arch)
765765 }
766766}
767767
768+ // / \brief Parses the `object_bits` argument from the command line arguments.
769+ // / \param argument The command line argument to parse the `object_bits` from.
770+ // / \param pointer_width The width of a pointer in bits. This is used to check
771+ // / the value of object_bits is within the valid range.
772+ // / \return A `bv_encodingt` on successful parsing. In the case where an invalid
773+ // / argument is specified, an `invalid_command_line_argument_exceptiont` will
774+ // / be thrown.
775+ configt::bv_encodingt parse_object_bits_encoding (
776+ const std::string &argument,
777+ const std::size_t pointer_width)
778+ {
779+ const auto throw_for_reason = [&](const std::string &reason) {
780+ throw invalid_command_line_argument_exceptiont (
781+ " Value of \" " + argument + " \" given for object-bits is " + reason +
782+ " . object-bits must be positive and less than the pointer width (" +
783+ std::to_string (pointer_width) + " ) " ,
784+ " --object_bits" );
785+ };
786+ const auto object_bits = string2optional<unsigned int >(argument);
787+ if (!object_bits)
788+ throw_for_reason (" not a valid unsigned integer" );
789+ if (*object_bits == 0 || *object_bits >= pointer_width)
790+ throw_for_reason (" out of range" );
791+
792+ configt::bv_encodingt bv_encoding;
793+ bv_encoding.object_bits = *object_bits;
794+ bv_encoding.is_object_bits_default = false ;
795+ return bv_encoding;
796+ }
797+
768798bool configt::set (const cmdlinet &cmdline)
769799{
770800 // defaults -- we match the architecture we have ourselves
771801
772802 cpp.cpp_standard =cppt::default_cpp_standard ();
773803
774- bv_encoding.object_bits =bv_encoding.default_object_bits ;
775- // This will allow us to override by language defaults later.
776- bv_encoding.is_object_bits_default =true ;
777-
778804 ansi_c.single_precision_constant =false ;
779805 ansi_c.for_has_scope =true ; // C99 or later
780806 ansi_c.ts_18661_3_Floatn_types =false ;
@@ -1078,19 +1104,8 @@ bool configt::set(const cmdlinet &cmdline)
10781104
10791105 if (cmdline.isset (" object-bits" ))
10801106 {
1081- bv_encoding.object_bits =
1082- unsafe_string2unsigned (cmdline.get_value (" object-bits" ));
1083-
1084- if (!(0 <bv_encoding.object_bits &&
1085- bv_encoding.object_bits <ansi_c.pointer_width ))
1086- {
1087- throw invalid_command_line_argument_exceptiont (
1088- " object-bits must be positive and less than the pointer width (" +
1089- std::to_string (ansi_c.pointer_width ) + " ) " ,
1090- " --object_bits" );
1091- }
1092-
1093- bv_encoding.is_object_bits_default = false ;
1107+ bv_encoding = parse_object_bits_encoding (
1108+ cmdline.get_value (" object-bits" ), ansi_c.pointer_width );
10941109 }
10951110
10961111 if (cmdline.isset (" malloc-fail-assert" ) && cmdline.isset (" malloc-fail-null" ))
0 commit comments