Skip to content

Type bug in reduce32 #109

@spth

Description

@spth

There is a type bug in reduce32 in reduce.c:

int32_t reduce32(int32_t a) {
  int32_t t;

  t = (a + (1 << 22)) >> 23;
  t = a - t*Q;
  return t;
}

The type of 1 is int, thus depending on the number of bits in an int (at least 16), (1 << 22) is undefined. Indeed, compiling this with SDCC, we see them both become 0, which I don't think was intended. The fix is simple: replace both 1 with 1l to change the type to long, which has at least 32 bits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions