Changeset 17c14273 in mainline


Ignore:
Timestamp:
2018-01-17T18:11:05Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e347396
Parents:
2467b41
Message:

Work around SPARC's multiplication insanity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/strtol.c

    r2467b41 r17c14273  
    5555        }
    5656        return INT_MAX;
     57}
     58
     59/* FIXME: workaround for GCC "optimizing" the overflow check
     60 * into soft-emulated 128b multiplication using `__multi3`,
     61 * which we don't currently implement.
     62 */
     63__attribute__((noinline)) static uintmax_t _max_value(int base)
     64{
     65        return UINTMAX_MAX / base;
    5766}
    5867
     
    111120
    112121        uintmax_t result = 0;
     122        uintmax_t max = _max_value(base);
    113123        int digit;
    114124
    115125        while (digit = _digit_value(*nptr), digit < base) {
    116126
    117                 if (__builtin_mul_overflow(result, base, &result) ||
    118                     __builtin_add_overflow(result, digit, &result)) {
     127                if (result > max ||
     128                    __builtin_add_overflow(result * base, digit, &result)) {
    119129
    120130                        errno = ERANGE;
Note: See TracChangeset for help on using the changeset viewer.