HomePhabricator

Avoid the use of abs64 in timedata

Description

Avoid the use of abs64 in timedata

Summary:
Issue core#20135:

When extending the test/fuzz/integer fuzzer I noticed the following UBSan warning when fuzzing abs64(...):

runtime error: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself

Typically abs(I n) type functions are not defined when n == std::numeric_limits<I>::min() so it could be argued that this is expected, but perhaps the function could be rewritten in a way which guarantees that it gives the same behaviour across systems (instead of UB).

This is a backport of core#20141

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10460

Details

Provenance
Pieter Wuille <pieter@wuille.net>Authored on Oct 13 2020, 00:36
PiRKCommitted on Nov 12 2021, 07:00
PiRKPushed on Nov 12 2021, 07:00
Reviewer
Restricted Project
Differential Revision
D10460: Avoid the use of abs64 in timedata
Parents
rABC2e6b0a0fe594: [Cashtab] Cosmetic update for message signing component
Branches
Unknown
Tags
Unknown