DescriptionStringToNumber: Fix integer overflow on parsing INT_MIN.
This patch adjusts the algorithm of toIntegralType(), which parses an integer
value out of a string. Previously, toIntegralType() used a positive number
as an accumulator regardless of whether we had seen the negative sign or not,
and it inverted the accumulator value if there had been a negative sign. This
causes an integer overflow when INT_MIN is specified as the source string,
because the absolute value of INT_MIN is one larger than that of INT_MAX.
This patch fixes this issue by accumulating a negative value if the result
will be negative. Also, the detection algorithm of overflows is updated so
that it can detect overflows correctly in every possible case (it used to have
a small bug that the function fails to parse INT_MIN in base 16).
Additionally, unit tests are added.
BUG=665110
Committed: https://crrev.com/957b5b3085eeae5a6fd6779d62feb90cc2515ad2
Cr-Commit-Position: refs/heads/master@{#437508}
Patch Set 1 #Patch Set 2 : Fix MSVC warning. #
Messages
Total messages: 19 (12 generated)
|