Skip to content

assert: Fix EqualValues to handle overflow/underflow - #1531

Merged
brackendawson merged 1 commit into
stretchr:masterfrom
arjunmahishi:fix-equal-values
Feb 14, 2024
Merged

assert: Fix EqualValues to handle overflow/underflow#1531
brackendawson merged 1 commit into
stretchr:masterfrom
arjunmahishi:fix-equal-values

Conversation

@arjunmahishi

@arjunmahishi arjunmahishi commented Feb 10, 2024

Copy link
Copy Markdown
Collaborator

Summary

The underlying function ObjectsAreEqualValues did not handle overflow/underflow of values while converting one type to another for comparison. For example:

    EqualValues(t, int(270), int8(14))

would return true, even though the values are not equal. Because, when you convert int(270) to int8, it overflows and becomes 14 (270 % 256 = 14)

Changes

This commit fixes that by making sure that the conversion always happens from the smaller type to the larger type, and then comparing the values. Additionally, this commit also separates out the test cases of ObjectsAreEqualValues from TestObjectsAreEqual.

Related issues

Closes #1462

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert.EqualValues About equality bug pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert: EqualValues does not check for overflows

4 participants