Take the boundary of signed negative values into account( Fix issue 1301) (#1336)

* Take the high boundary of signed negative values into account

* UI unit tests for the Copy/Paste menu are added

* Additional corner case for the number notations without negative values
This commit is contained in:
Jack Rainy
2020-09-15 01:11:17 +03:00
committed by GitHub
parent c508cc29ed
commit d256fb6c19
4 changed files with 151 additions and 7 deletions

View File

@@ -310,6 +310,9 @@ bool CopyPasteManager::ExpressionRegExMatch(
if (operandMatched)
{
// Remember the sign of the operand
bool isNegativeValue = operand->Data()[0] == L'-';
// Remove characters that are valid in the expression but we do not want to include in length calculations
// or which will break conversion from string-to-ULL.
auto operandValue = SanitizeOperand(operand);
@@ -332,7 +335,11 @@ bool CopyPasteManager::ExpressionRegExMatch(
break;
}
if (operandAsULL->Value > maxOperandLengthAndValue.maxValue)
// Calculate how much we exceed the maxValue.
// In case we exceed it for 1 only, and working with negative number - that's a corner case for max signed values (e.g. -32768)
bool isOverflow = operandAsULL->Value > maxOperandLengthAndValue.maxValue;
bool isMaxNegativeValue = operandAsULL->Value - 1 == maxOperandLengthAndValue.maxValue;
if (isOverflow && !(isNegativeValue && isMaxNegativeValue))
{
expMatched = false;
break;