@@ -765,6 +765,32 @@ 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 unsigned int object_bits = unsafe_string2unsigned (argument);
780+ if (object_bits <= 0 || object_bits >= pointer_width)
781+ {
782+ throw invalid_command_line_argument_exceptiont (
783+ " object-bits must be positive and less than the pointer width (" +
784+ std::to_string (pointer_width) + " ) " ,
785+ " --object_bits" );
786+ }
787+
788+ configt::bv_encodingt bv_encoding;
789+ bv_encoding.object_bits = object_bits;
790+ bv_encoding.is_object_bits_default = false ;
791+ return bv_encoding;
792+ }
793+
768794bool configt::set (const cmdlinet &cmdline)
769795{
770796 // defaults -- we match the architecture we have ourselves
@@ -1074,19 +1100,8 @@ bool configt::set(const cmdlinet &cmdline)
10741100
10751101 if (cmdline.isset (" object-bits" ))
10761102 {
1077- bv_encoding.object_bits =
1078- unsafe_string2unsigned (cmdline.get_value (" object-bits" ));
1079-
1080- if (!(0 <bv_encoding.object_bits &&
1081- bv_encoding.object_bits <ansi_c.pointer_width ))
1082- {
1083- throw invalid_command_line_argument_exceptiont (
1084- " object-bits must be positive and less than the pointer width (" +
1085- std::to_string (ansi_c.pointer_width ) + " ) " ,
1086- " --object_bits" );
1087- }
1088-
1089- bv_encoding.is_object_bits_default = false ;
1103+ bv_encoding = parse_object_bits_encoding (
1104+ cmdline.get_value (" object-bits" ), ansi_c.pointer_width );
10901105 }
10911106
10921107 if (cmdline.isset (" malloc-fail-assert" ) && cmdline.isset (" malloc-fail-null" ))
0 commit comments