Skip to content

Fix operator precedence bug in datagram ACK timeout calculation - #309

Merged
dpharris merged 1 commit into
masterfrom
bracz-timeout-fix
Sep 25, 2026
Merged

dpharris merged 1 commit into
masterfrom
bracz-timeout-fix

Conversation

@balazsracz

Copy link
Copy Markdown
Collaborator

In MemoryConfigurationService, 1 << (flags & 0x0F) * 1000 evaluated the multiplication before the bitwise shift due to Java operator precedence. This caused the exponent $N$ to shift by $(N \times 1000) \pmod{32}$, yielding incorrect timeout intervals (e.g., 256 ms instead of 2 s for $N=1$, and 65.5 s instead of 4 s for $N=2$).

Parenthesize the shift operation to compute $(1 \ll N) \times 1000\text{ ms}$ per the OpenLCB Datagram Transport Standard, and add corresponding unit tests.

In `MemoryConfigurationService`, `1 << (flags & 0x0F) * 1000` evaluated the
multiplication before the bitwise shift due to Java operator precedence.
This caused the exponent $N$ to shift by $(N \times 1000) \pmod{32}$, yielding
incorrect timeout intervals (e.g., 256 ms instead of 2 s for $N=1$, and 65.5 s
instead of 4 s for $N=2$).

Parenthesize the shift operation to compute $(1 \ll N) \times 1000\text{ ms}$
per the OpenLCB Datagram Transport Standard, and add corresponding unit tests.
@dpharris
dpharris merged commit 1b0951b into master Sep 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants