Neels Hofmeyr has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/10066 )

Change subject: utils_test: fix isqrt_test calculation range
......................................................................

utils_test: fix isqrt_test calculation range

Multiplying the uint16_t x by itself seems to default to be calculated in
int32_t range, while it obviously needs uint32_t. This causes sporadic
sanitizer barfs:

    Testing integer square-root
    utils_test.c:445:18: runtime error: signed integer overflow: 60369 * 60369 
cannot be represented in type 'int'

The final result is still correct, because it is in fact interpreted as 
uint32_t.

Cast to uint32_t to make sure the sanitizer doesn't complain.

Related: OS#3407
Change-Id: I83c14e38deaa466d977ee43c9420534ed90f090d
---
M tests/utils/utils_test.c
1 file changed, 1 insertion(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c
index cb4e476..84964f5 100644
--- a/tests/utils/utils_test.c
+++ b/tests/utils/utils_test.c
@@ -439,7 +439,7 @@
                        x = r * (UINT16_MAX/RAND_MAX);
                else
                        x = r;
-               uint32_t sq = x*x;
+               uint32_t sq = (uint32_t)x*x;
                uint32_t y = osmo_isqrt32(sq);
                if (y != x)
                        printf("ERROR: x=%u, sq=%u, osmo_isqrt(%u) = %u\n", x, 
sq, sq, y);

--
To view, visit https://gerrit.osmocom.org/10066
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I83c14e38deaa466d977ee43c9420534ed90f090d
Gerrit-Change-Number: 10066
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <[email protected]>

Reply via email to