Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/84575?usp=email )
Change subject: util/lint: Use bigint for hexadecimal values in handle_range ......................................................................
util/lint: Use bigint for hexadecimal values in handle_range
The `handle_range` function in `kconfig_lint` was failing to correctly handle large hexadecimal values (64-bit value) due to limitations with Perl's handling of standard integers.
This commit modifies the function to use the `bigint` pragma, enabling it to handle arbitrarily large integers. This prevents issues with 64-bit hexadecimal values and ensures accurate comparisons for range validation.
Change-Id: I402bb9bec9ba5bfb79b4185f35228c41d4a7b674 Signed-off-by: Subrata Banik subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/84575 Reviewed-by: Karthik Ramasubramanian kramasub@google.com Reviewed-by: Christian Walter christian.walter@9elements.com Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M util/lint/kconfig_lint 1 file changed, 13 insertions(+), 7 deletions(-)
Approvals: Christian Walter: Looks good to me, approved Karthik Ramasubramanian: Looks good to me, approved build bot (Jenkins): Verified
diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint index 43b1630..21e40c6 100755 --- a/util/lint/kconfig_lint +++ b/util/lint/kconfig_lint @@ -856,18 +856,24 @@ my $expression; ( $range2, $expression ) = handle_if_line( $range2, $inside_config, $filename, $line_no );
+ # Use bigint for large hexadecimal values + use bigint; $range1 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/; - my $checkrange1 = $1; + my $checkrange1 = Math::BigInt->new($1); $range2 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/; - my $checkrange2 = $1; + my $checkrange2 = Math::BigInt->new($1);
- if ( $checkrange1 && $checkrange2 && ( hex($checkrange1) > hex($checkrange2) ) ) { + if ( $checkrange1 && $checkrange2 && ( $checkrange1 > $checkrange2 ) ) { show_error("Range entry in $filename line $line_no value 1 ($range1) is greater than value 2 ($range2)."); }
if ($inside_config) { if ( exists( $symbols{$inside_config}{range1} ) ) { - if ( ( $symbols{$inside_config}{range1} != $range1 ) || ( $symbols{$inside_config}{range2} != $range2 ) ) { + # Convert existing range values to BigInt objects + $symbols{$inside_config}{range1} = Math::BigInt->new($symbols{$inside_config}{range1}); + $symbols{$inside_config}{range2} = Math::BigInt->new($symbols{$inside_config}{range2}); + + if ( ( $symbols{$inside_config}{range1} != $checkrange1 ) || ( $symbols{$inside_config}{range2} != $checkrange2 ) ) { if ($show_note_output) { print "#!!!!! Note: Config '$inside_config' range entry $range1 $range2 at $filename:$line_no does"; print " not match the previously defined range $symbols{$inside_config}{range1}" @@ -877,9 +883,9 @@ } } else { - $symbols{$inside_config}{range1} = $range1; - $symbols{$inside_config}{range2} = $range2; - $symbols{$inside_config}{range_file} = $filename; + $symbols{$inside_config}{range1} = $checkrange1; + $symbols{$inside_config}{range2} = $checkrange2; + $symbols{$inside_config}{range_file} = $filename; $symbols{$inside_config}{range_line_no} = $line_no; } }