From caefaaa093eaff7cba9cdd4d4b6bfd987890ea15 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Sat, 28 Sep 2024 03:36:18 +0000 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/84575 Reviewed-by: Karthik Ramasubramanian Reviewed-by: Christian Walter Tested-by: build bot (Jenkins) --- util/lint/kconfig_lint | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint index 43b1630fc0..21e40c6aa4 100755 --- a/util/lint/kconfig_lint +++ b/util/lint/kconfig_lint @@ -856,18 +856,24 @@ sub handle_range { 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 @@ sub handle_range { } } 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; } } -- cgit v1.2.3