diff options
author | Subrata Banik <subratabanik@google.com> | 2024-09-28 03:36:18 +0000 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2024-10-01 21:35:20 +0000 |
commit | caefaaa093eaff7cba9cdd4d4b6bfd987890ea15 (patch) | |
tree | dbfa474c2abbc33f7aed6bd892b56e64a365b47f | |
parent | c74de0dea765159e9d7b2f3541b389e95012e063 (diff) |
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>
-rwxr-xr-x | util/lint/kconfig_lint | 20 |
1 files 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; } } |