Skip to content

Fix sign handling when converting hex offsets to integer - #1776

Merged
larshp merged 3 commits into
mainfrom
copilot/fix-converting-hex-to-int
Jul 30, 2026
Merged

Fix sign handling when converting hex offsets to integer#1776
larshp merged 3 commits into
mainfrom
copilot/fix-converting-hex-to-int

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Converting a hex value to i only applied two's complement when the source was a Hex/HexUInt8 field of length >= 4. Offsetting a hex field returns an XString, so the sign bit was ignored:

DATA lv_hex TYPE x LENGTH 5 VALUE '00FFFFFFFF'.
DATA lv_int TYPE i.
lv_int = lv_hex+1.
ASSERT lv_int = -1.   " was 4294967295

Changes

  • packages/runtime/src/types/integer.ts: set() now derives the byte length from the hex string itself instead of getLength(), so Hex, HexUInt8 and XString are treated uniformly. Values of 4 bytes or more are interpreted as two's complement; shorter values (e.g. lv_hex+1(2)65535) remain unsigned.
  • test/types/integer.ts: cases for x LENGTH 4 = 'FFFFFFFF', the offset case above, and a 2-byte offset that must stay positive.

Note that Hex.getOffset() returning XString discards the original length, which is why the type-based check was insufficient.

Copilot AI linked an issue Jul 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix bug in converting hex to int Fix sign handling when converting hex offsets to integer Jul 30, 2026
Copilot AI requested a review from larshp July 30, 2026 11:10
@github-actions

Copy link
Copy Markdown

Regression test results:

Repository Result Runtime
abap-openapi/abap-openapi 🟢 12s
abapGit/abapGit 🟢 12s
heliconialabs/abap-opentelemetry 🟢 4s
heliconialabs/abap-protobuf 🟢 5s
larshp/abap-advent-2020 🟢 4s
larshp/abap-wasm 🟢 4s
larshp/abapNTLM 🟢 5s
larshp/abapPGP 🟢 89s
oisee/zork-abap 🟢 5s
open-abap/open-abap-core 🟢 4s
open-abap/open-abap-gui 🟢 5s
open-abap/open-abap-jobs 🟢 13s
open-abap/open-abap-lock 🟢 12s
open-abap/open-abap-odata 🟢 6s
open-abap/open-table-maintenance 🟢 11s
SAP/abap-file-formats-tools 🟢 12s
Sumu-Ning/AES 🟢 5s

Performance test results:

Performance Before After Delta
1: APPEND and DELETE 486ms 490ms 4 🟢
2: READ TABLE, table_line 515ms 512ms -3 🟢
3: LOOP USING KEY 525ms 515ms -10 🟢
4: Copy, same sorting 114ms 114ms 0 🟢
5: Copy, becomes sorted 34ms 31ms -3 🟢
6: INSERT INDEX 1 370ms 372ms 2 🟢
7: APPEND matching types 211ms 215ms 4 🟢
8: READ TABLE BINARY SEARCH 35ms 33ms -2 🟢
9: INSERT INTO TABLE hashed 255ms 243ms -12 🟢
10: DELETE ADJACENT 865ms 850ms -15 🟢
11: READ WITH TABLE KEY HASHED 127ms 127ms 0 🟢
12: READ WITH KEY HASHED, primary 193ms 192ms -1 🟢
13: INSERT INTO TABLE standard 21ms 20ms -1 🟢
14: Constant characters 35ms 36ms 1 🟢
15: Compare characters 61ms 57ms -4 🟢
16: Method number 5 🎶 401ms 388ms -13 🟢
17: Substring and find negative 117ms 112ms -5 🟢
18: CO compare 103ms 101ms -2 🟢
19: Call method, compatible structure 54ms 55ms 1 🟢
20: Call method, identical structure 12ms 11ms -1 🟢
21: CASE many char constants 167ms 168ms 1 🟢
22: READ TABLE WITH KEY secondary 26ms 29ms 3 🟢
23: CASE many int constants 172ms 171ms -1 🟢
24: Copy table contents 129ms 131ms 2 🟢
25: READ TABLE, not found 13ms 13ms 0 🟢
26: REPLACE OCCURRENCES, simple 66ms 68ms 2 🟢
27: READ TABLE, building hash 40ms 40ms 0 🟢
28: CONCATENATE 1ms 1ms 0 🟢
29: Write Hex to Hex via offset 972ms 974ms 2 🟢
30: Get Hex from Hex via offset 5ms 6ms 1 🟢
31: SET BIT hex 532ms 529ms -3 🟢
32: GET BIT hex 431ms 457ms 26 🟢
33: Compare Hex 371ms 383ms 12 🟢
34: Basic CONCATENATE 36ms 36ms 0 🟢
35: gt 193ms 192ms -1 🟢
36: CLEAR char 130ms 131ms 1 🟢
37: CLEAR numc 121ms 123ms 2 🟢
38: Structure copy and APPEND 385ms 400ms 15 🟢
39: eq int 677ms 651ms -26 🟢
40: eq string 601ms 596ms -5 🟢
41: eq char, different lengths 94ms 96ms 2 🟢
42: eq int with numc 85ms 87ms 2 🟢

Updated: 2026-07-30T11:23:42.218Z

SHA: ce2e5e0

@larshp
larshp marked this pull request as ready for review July 30, 2026 11:28
@larshp
larshp enabled auto-merge (squash) July 30, 2026 11:28
@larshp
larshp merged commit 5adbe3b into main Jul 30, 2026
4 checks passed
@larshp
larshp deleted the copilot/fix-converting-hex-to-int branch July 30, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

bug, converting hex to int

2 participants