Skip to content

Commit b683572

Browse files
committed
fix: Use strtoull so so that 32 bits values are handled correctly
gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_non_decimal_int_literal): strtoull insted strtol Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
1 parent 727c030 commit b683572

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gcc/rust/lex/rust-lex.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,11 @@ Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,
22712271
}
22722272

22732273
// convert value to decimal representation
2274-
long dec_num = std::strtol (existent_str.c_str (), nullptr, base);
2274+
// Use strtoull so that values like 0xFFFFFFFF are handled correctly on
2275+
// 32-bit hosts where |long| is only 32 bits and strtol would clamp to
2276+
// LONG_MAX (0x7FFFFFFF) instead of preserving the full unsigned value.
2277+
unsigned long long dec_num
2278+
= std::strtoull (existent_str.c_str (), nullptr, base);
22752279

22762280
existent_str = std::to_string (dec_num);
22772281

0 commit comments

Comments
 (0)